Created
July 1, 2014 18:42
-
-
Save fernandofleury/f6d9c05ba76ccd5bb2ee to your computer and use it in GitHub Desktop.
prototypejs
This file contains 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
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