Created
September 24, 2015 13:47
-
-
Save fschell/e7629b0a2654f1ff0342 to your computer and use it in GitHub Desktop.
Immediately-Invoked Function Expression (IIFE)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IIFE | |
(function(){ /* code */ }()); // Crockford recommends this one | |
(function(){ /* code */ })(); // But this one works just as well | |
// if you use mootools and jQuery in compat mode and mootools exposes $ and jQuery jQuery like so: | |
<script src="mootools.js"></script> | |
<script src="jquery.js"></script> | |
var jQuery = jQuery.noConflict(); | |
// then you can use legacy code which uses jQuery like so | |
(function($){ | |
// $ === jQuery | |
// your legacy code here | |
})(jQuery); | |
// and legacy code which uses mootools like so: | |
(function($){ | |
// $ === mootools | |
// your legacy code here | |
})($); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment