Skip to content

Instantly share code, notes, and snippets.

@fschell
Created September 24, 2015 13:47
Show Gist options
  • Save fschell/e7629b0a2654f1ff0342 to your computer and use it in GitHub Desktop.
Save fschell/e7629b0a2654f1ff0342 to your computer and use it in GitHub Desktop.
Immediately-Invoked Function Expression (IIFE)
// 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