IIFE invocation in JavaScript
That depends on where the code is executed.
.call(this)
explicitly sets the this
to the object you pass to .call
. Only using ();
will set this
to window
(or to undefined
in strict mode).
If the code is executed in global scope it will be the same. If not, then you will get different results if this
does not refer to window
(or is undefined
).
Example:
var obj = {
foo: function() {
(function(){
console.log(this); // this === obj
}).call(this); // this === obj
(function(){
console.log(this); // this === window
})();
}
};
obj.foo();
More information about this
on MDN