The concept of explicit binding refers to the use of methods such as
.call
, .apply
, and .bind
in JavaScript to specify the value of the this
keyword within a function.- The
.call
method allows you to specify the context by passing the object you want as the value ofthis
as the first argument, followed by any additional arguments for the function.
- The
.apply
method works similarly to.call
, but instead of passing additional arguments directly, you pass an array that contains the arguments.
- The
.bind
method returns a reference to a new function with a specified context, but it does not immediately invoke the function like.call
and.apply
.
It is important to note that if you use strict mode, using the
this
keyword without binding it explicitly will result in an error and the this
value will be set to the window object. Additionally, without explicit binding, this
will always refer to the window object.Explicit binding examples with .call, .apply and .bind
Β
first param is the this context and the others are the params of the function
Β
Β
Β
Β