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?
beaker
16.9k3 gold badges36 silver badges53 bronze badges
asked Mar 16, 2016 at 18:38
Sivasankar Saravanan
455 bronze badges
1 Answer 1
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.
answered Mar 16, 2016 at 18:40
Jonathan.Brink
25.3k20 gold badges85 silver badges127 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
.call?