Explicit Binding rule for this keyword in JS

Memosha Sinha
1 min readSep 16, 2019

--

This is part of the series this keyword in Javascript

Image we have a use case where function call uses a particular object for “this binding” without putting a property function reference.
Vast majority of functions have access to call(…) and apply(…). How do these work?
They both take object to use for “this” as first parameter and then invoke the function with that object. As we mention what object is being used for this, its “explicit binding”.

function explicitBinding(){
console.log("Explicit Binding");
}
var obj = {
a: 2
};
explicitBinding.call(obj);
If primitive value is passed as this, its wrapped in its object form
(new String(), new Boolean()...) known as Boxing.

Reference to call

apply

Hard Binding

function binding(){
console.log("Hard Binding", this.a);
}
var obj = {
a: 2
};
var hardBinding = function(){
binding.call(obj);
}
hardBinding();//2
No matter how hardBinding is invoked later, binding will always be called with obj.

--

--

Memosha Sinha

Software Engineer, Fitness lover, Traveller, wanderlust, optimistic