Skip to content

Instantly share code, notes, and snippets.

@dutradotdev
Last active March 18, 2019 22:19
Show Gist options
  • Save dutradotdev/309e2914db666b07254bc2bc9f763a13 to your computer and use it in GitHub Desktop.
Save dutradotdev/309e2914db666b07254bc2bc9f763a13 to your computer and use it in GitHub Desktop.
Herança
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