Created
April 20, 2013 17:35
-
-
Save julsfelic/5426762 to your computer and use it in GitHub Desktop.
Scope safe constructor example
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
function Person(name, age, job) { | |
if (this instanceof Person) { | |
this.name = name; | |
this.age = age; | |
this.job = job; | |
} else { | |
return new Person(name, age, job) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment