Skip to content

Instantly share code, notes, and snippets.

@julienetie
Last active July 4, 2020 15:43
Show Gist options
  • Save julienetie/3d152d50a6308b5ccf2111f4822cbfad to your computer and use it in GitHub Desktop.
Save julienetie/3d152d50a6308b5ccf2111f4822cbfad to your computer and use it in GitHub Desktop.
/* Object Oriented JavaScript */
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
constructor(name) {
super(name); // call the super class constructor and pass in the name parameter
}
speak() {
console.log(`${this.name} barks.`);
}
}
/*
let d = new Dog('Mitzie');
d.speak(); // Mitzie barks.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment