Search code examples
javascriptjquerymemory-efficientiifeself-invoking-function

What's more memory efficient IIFE in javascript?


I want to invoke an anonymous self-executing function, only when dom is ready, with the more memory-efficient technique. And also, I want to use locally-scoped versions of window and window.jQuery global Objects, for optimization (loading local scope it's faster than global).

So, it's this pattern correct?

;!(function(window, $) {
    $(function(){
        // your code here
    }); 
})(window,window.jQuery);

I'm not sure if I'm doing something wrong ...

Thanks in advance!


Solution

  • Would just look a little better IMO:

    ;(function(window, $, undefined) {
        $(function(){
           // your code here
        }); 
    })(window,jQuery);