Skip to content

Instantly share code, notes, and snippets.

@queckezz
Last active December 16, 2015 11:39
Show Gist options
  • Save queckezz/5429046 to your computer and use it in GitHub Desktop.
Save queckezz/5429046 to your computer and use it in GitHub Desktop.
instantiate a function without using the 'new' keyword
function constructor( args ) {
if( !(this instanceof constructor) ) return new constructor( args );
// ... constructor stuff
}
constructor.prototype.method() {};
constructor.method();
/*
* instead of:
* new constructor;
* constructor.method();
* Just:
* constructor.method();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment