Skip to content

Instantly share code, notes, and snippets.

@anurag-majumdar
Created April 16, 2018 10:10
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/67e79e659f815b594661c6bca348ee53 to your computer and use it in GitHub Desktop.
Save anurag-majumdar/67e79e659f815b594661c6bca348ee53 to your computer and use it in GitHub Desktop.
function Animal(name, weight) {
this.name = name;
this.weight = weight;
}
Animal.prototype.eat = function() {
return `${this.name} is eating!`;
}
Animal.prototype.sleep = function() {
return `${this.name} is going to sleep!`;
}
Animal.prototype.wakeUp = function() {
return `${this.name} is waking up!`;
}
function Gorilla(name, weight) {
Animal.call(this, name, weight);
}
Gorilla.prototype = Object.create(Animal.prototype);
Gorilla.prototype.constructor = Gorilla;
Gorilla.prototype.climbTrees = function () {
return `${this.name} is climbing trees!`;
}
Gorilla.prototype.poundChest = function() {
return `${this.name} is pounding its chest!`;
}
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)}`;
}
function display(content) {
console.log(content);
}
var gorilla = new Gorilla('George', '160Kg');
display(gorilla.poundChest());
display(gorilla.sleep());
display(gorilla.showVigour());
display(gorilla.dailyRoutine());
// OUTPUT:
// George is pounding its chest!
// George is going to sleep!
// George is eating! George is pounding its chest!
// George is waking up! George is pounding its chest! George is eating! George is going to sleep!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment