Skip to content

Instantly share code, notes, and snippets.

@aalvesjr
Created January 28, 2013 04:24
Show Gist options
  • Select an option

  • Save aalvesjr/4653019 to your computer and use it in GitHub Desktop.

Select an option

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", "blackmore@rocknroll.org");
// ou
var candice = User("Candice Night", "candice@rocknroll.org");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment