Skip to content

Instantly share code, notes, and snippets.

@GitHub-Mike
Forked from paulirish/gist:315916
Last active October 1, 2022 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GitHub-Mike/55027d81604da9bd39dea0e3194cd552 to your computer and use it in GitHub Desktop.
Save GitHub-Mike/55027d81604da9bd39dea0e3194cd552 to your computer and use it in GitHub Desktop.
// closure pattern
( function( window, document, undefined ) {
console.log('Hello world!');
})( this,this.document );
// single-lettered minified version
(function(w,d,u){console.log('Hello world!');})(this,this.document);
// self executing anonymous function
(function(){})()
// bypassing a var declaration at the top and `this` is always the global object when in global scope
(function(myname){})('paul')
// switch up the args passed in on all ready functions
( function( oReady ) {
$.fn.ready = function( fn ) {
return oReady.call( this, function() { fn.call( this, $, window, document ); });
};
})( $.fn.ready );
// which enables
$(function($,window,document,undefined){ alert(document) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment