Skip to content

Instantly share code, notes, and snippets.

@fernandofleury
Created July 1, 2014 18:42
Show Gist options
  • Save fernandofleury/f6d9c05ba76ccd5bb2ee to your computer and use it in GitHub Desktop.
Save fernandofleury/f6d9c05ba76ccd5bb2ee to your computer and use it in GitHub Desktop.
prototypejs
var Car = function(model, color) {
this.model = model;
this.color = color;
}
var fusca = new Car('fusca', 'amarelo');
// A partir do construtor clássico os métodos/propriedades são fixos ao momento de criação, o que não é o caso com protótipos.
fusca.horn();
// undefined is not a function
Car.prototype.horn = function() {
return 'buzinada';
}
fusca.horn();
// buzinada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment