-
-
Save dutradotdev/309e2914db666b07254bc2bc9f763a13 to your computer and use it in GitHub Desktop.
Herança
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
function Veiculo(nome, valor, cor) { | |
this.nome = nome; | |
this.valor = valor; | |
this.cor = 'preto'; | |
}; | |
Veiculo.prototype.acelerar = function() { | |
console.log('aceleraaaaaa'); | |
} | |
function Ferrari() { | |
// A "classe" Veiculo é chamada usando o contexto existente dentro de Ferrari... ou seja | |
// todos os atributos da classe serão adicionados ao this de Ferrari | |
Veiculo.call(this); | |
this.marca = 'Ferrari'; | |
} | |
Ferrari.prototype.acelereComoUmaFerrari = function() { | |
console.log('ACELERAAAAAAAA FERRARI'); | |
} | |
let f = new Ferrari(); | |
f.acelereComoUmaFerrari(); // ACELERAAAAAAAA FERRARI | |
f.acelerar(); // TypeError: f.acelerar is not a function | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment