September 10, 2013
The need for JS functions which are self executing?
Bhb’s Question:
What is the use of functions which self execute?
(function(w,d) {...})(window, document);
And why do they pass window/document which are global functions?
Why do they pass window/document which are global functions?
So that inside that function scope window and document will be available as w and d.
One of the common practice of this is included with jQuery plugin development as:
(function($) {
//...
})(jQuery);
Since $ can be used in prototype too, this can create anamolities when mixing two libraries, but inside above function, $ will only represent jQuery but not prototype.