Created
April 16, 2018 10:10
-
-
Save anurag-majumdar/67e79e659f815b594661c6bca348ee53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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