Skip to content

Instantly share code, notes, and snippets.

@aalvesjr
Created January 28, 2013 04:24
Show Gist options
  • Save aalvesjr/4653019 to your computer and use it in GitHub Desktop.
Save aalvesjr/4653019 to your computer and use it in GitHub Desktop.
Curiosidade sobre o construtor new no JS
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