Created
March 28, 2012 17:55
-
-
Save aaronmccall/2228728 to your computer and use it in GitHub Desktop.
Javascript instance without new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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