Reputation: 45
var tempFn = function(someText){
console.log(someText);
}
tempFn('siva');
// where I simply call the function with text 'siva'
vs.
tempFn.call(this,'siva');
// where I call the function using call method
What is the difference between these approaches?
Upvotes: 2
Views: 1038
Reputation: 25413
When you use the call
form you are being explicit about the context that the function will be invoked with.
The context will determine what the value of this
is when your function executes.
In your case, you are passing in this
which would be the default anyway, so it's a no-op. Also, your tempFn
function doesn't invoke the this
keyword so it wouldn't matter anyway if you passed in a different scope.
Upvotes: 3