Skip to content

Instantly share code, notes, and snippets.

@aaronmccall
Created March 28, 2012 17:55
Show Gist options
  • Save aaronmccall/2228728 to your computer and use it in GitHub Desktop.
Save aaronmccall/2228728 to your computer and use it in GitHub Desktop.
Javascript instance without new
// Constructor function makes a Person model
var Person = function (lastName, firstName) {
// What's that? I'm not feeling like myself today!
if (!(this instanceof Person)) {
// Just call myself with new then!
return new Person(lastName, firstName);
}
this.lastName = lastName;
this.firstName = firstName;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment