Skip to content

Instantly share code, notes, and snippets.

@dutradotdev
Last active March 18, 2019 23:52
Show Gist options
  • Save dutradotdev/e2d1c0e40f6f160d4e5364049345f8c9 to your computer and use it in GitHub Desktop.
Save dutradotdev/e2d1c0e40f6f160d4e5364049345f8c9 to your computer and use it in GitHub Desktop.
Herança + ES6
class Veiculo {
constructor(nome, valor, cor) {
this._nome = nome;
this._valor = valor;
this._cor = cor;
}
get cor() {
return this._cor;
}
set cor(cor) {
this._cor = cor;
}
static frear() {
console.log('Freiando!!');
}
acelerar() {
console.log('aceleraaaaaa');
}
}
class Ferrari extends Veiculo {
constructor() {
super();
this.marca = 'Ferrari';
}
acelereComoUmaFerrari() {
console.log('ACELERAAAAAAAA FERRARI');
}
}
let f = new Ferrari();
f.acelereComoUmaFerrari(); // works!
f.acelerar(); // works!
Ferrari.prototype.constructor; // Ferrari
f.cor = 'azul'; // works!
Veiculo.frear(); // works!
Ferrari.frear(); // works!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment