The first form is passed in the parameter, and the second form sets what 'this' means inside the executing function. They are different.
(function(x){ console.log(this,x); })( jQuery ); //--> [window object] //--> [jQuery object] (function(x){ console.log(this,x); }).call( jQuery ); //--> [jQuery object] //--> undefined (function(x){ console.log(this,x); }).call( jQuery, jQuery ); //--> [jQuery object] //--> [jQuery object]
See Function.prototype.call and Function.prototype.apply for more information.
Here you can use the call technique:
v = 'oh noes!' var o = { v : 42, f : function(){ console.log(this.v); (function(){ console.log(this.v) })(); } }; of();
Without setting this through call() , the self-service function is called in the global area (window), not the current object.
Phrogz
source share