Skip to content

Instantly share code, notes, and snippets.

@anurag-majumdar
Last active April 16, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anurag-majumdar/211a6a2da55ff5ca6880cf90d4dc30e7 to your computer and use it in GitHub Desktop.
Save anurag-majumdar/211a6a2da55ff5ca6880cf90d4dc30e7 to your computer and use it in GitHub Desktop.
// ES6 style
class Gorilla extends Animal {
constructor(name, weight) {
super(name, weight);
}
showVigour() {
return `${super.eat()} ${this.poundChest()}`;
}
dailyRoutine() {
return `${super.wakeUp()} ${this.poundChest()} ${super.eat()} ${super.sleep()}`;
}
// ...
}
// Traditional style
function Gorilla(name, weight) {
Animal.call(this, name, weight);
}
Gorilla.prototype = Object.create(Animal.prototype);
Gorilla.prototype.constructor = Gorilla;
Gorilla.prototype.showVigour = function () {
return `${Animal.prototype.eat.call(this)} ${this.poundChest()}`;
}
Gorilla.prototype.dailyRoutine = function() {
return `${Animal.prototype.wakeUp.call(this)} ${this.poundChest()} ${Animal.prototype.eat.call(this)} ${Animal.prototype.sleep.call(this)}`;
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment