Created
January 28, 2013 04:24
-
-
Save aalvesjr/4653019 to your computer and use it in GitHub Desktop.
Curiosidade sobre o construtor new no JS
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(name, email) { | |
if (this.constructor !== User){ | |
return new User(name, email); | |
} | |
this.name = name; | |
this.email = email; | |
} | |
// Agora pode se criar um User assim: | |
var ritchie = new User("Ritchie", "[email protected]"); | |
// ou | |
var candice = User("Candice Night", "[email protected]"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment