Skip to content

Instantly share code, notes, and snippets.

@jinqian
Created January 15, 2014 17:19
Show Gist options
  • Select an option

  • Save jinqian/8440374 to your computer and use it in GitHub Desktop.

Select an option

Save jinqian/8440374 to your computer and use it in GitHub Desktop.
a very clean way to make sure your object is called as a constructor !
var Lawnchair = function (options, callback) {
// ensure Lawnchair was called as a constructor
if (!(this instanceof Lawnchair)) return new Lawnchair(options, callback);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment