javascript - Should I wrap jQuery document ready in a self executing function? -


i had thought this:

(function(window, undefined){     $ = window.jquery;     $(function(){         // stuff     });      })(this); 

would consider practice or bad? have implications when jquery(document).ready() fire?

only reason i'd if have javascript run before dom ready, , don't want pollute global namespace.

(function(window, undefined){     var $ = window.jquery;      // create variables and/or functions shouldn't global     //    ...and work before "ready()" fires     var = 'some value';     function b() {         // important stuff     }     var c = b();      // maybe set `.live()` handler, doesn't rely on dom ready.     $('.someselector').live( function() {         // handler code.         // works before dom ready.     });      $(function(){         // dom ready code     });      })(this); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -