3 ms·
What is the advantage of (function($){})(jQuery) over jQuery(function($){}) ? In either case the jQuery object must be in the namespace, and neither leaves a na
by LogicHoleFlaw 18y ago
What is the advantage of (function($){})(jQuery) over jQuery(function($){}) ? In either case the jQuery object must be in the namespace, and neither leaves a named function laying about. According to the jQuery API jQuery(callback) is sugar for $(document).ready(callback). The ready event is usually when I want my code to run...
http://docs.jquery.com/Core/jQuery#callback http://docs.jquery.com/Core/jQuery#callback
- humanchimp 18y agoThe (function($){...})(jQuery) syntax is used by plug-in developers who want their code to run before the jQuery(document).ready event. It is closure, and it's purpose in this case is to protect the global namespace from variables introduced by the script. Closures also have many other useful applications in JavaScript.