Created
August 12, 2014 08:12
-
-
Save send2moran/6b1660ec83310e8ec94b to your computer and use it in GitHub Desktop.
We need to make sure that the new operator is always used.
This file contains hidden or 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 User(first, last){ | |
if ( !(this instanceof User) ) | |
return new User(first, last); | |
this.name = first + " " + last; | |
} | |
var name = "Resig"; | |
var user = User("John", name); | |
assert( user, "This was defined correctly, even if it was by mistake." ); | |
assert( name == "Resig", "The right name was maintained." ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function User(first, last){
if ( !(this instanceof arguments.callee) )
return new User(first, last);
this.name = first + " " + last;
}