Reputation: 675
(function() {
console.log('immediately invoked function...');
}.call(this));
(function() {
console.log('immediately invoked function...');
}());
What is the difference between those 2 IIFE patterns?
Upvotes: 1
Views: 36
Reputation: 82734
The difference is, that in the .call()
case, the value of this
inside the IIFE is explicitly set (by .call()
's first argument). In the second case it is determined from the way the function is called.
Incidentally, in this case both are the same.
Upvotes: 3
Reputation: 74
In the upper example, the functions context (e.g the this
keyword) is set to the context that applies where the IIFE lives)
Upvotes: 0