Immediately-invoked function expressions

Protect your global environment from being polluted by your code with immediately-invoked function expressions (IIFE). Code within an IIFE is within its own lexical scope:

(function() {
  // your stuff here
})();

Passing in variables

You can pass variables in the IIFE's scope with something like this:

(function($) {
  // $ == jQuery;
})(jQuery);

Search

🔎 Searching...