View super.js
// ES6 style | |
class Gorilla extends Animal { | |
constructor(name, weight) { | |
super(name, weight); | |
} | |
showVigour() { | |
return `${super.eat()} ${this.poundChest()}`; | |
} |
View extends.js
// ES6 style | |
class Gorilla extends Animal { | |
constructor(name, weight) { | |
super(name, weight); | |
} | |
//... | |
} | |
// Traditional style | |
function Gorilla(name, weight) { |
View methods-comparison.js
// ES6 style | |
class Animal { | |
// ... | |
eat() { | |
return `${this.name} is eating!`; | |
} | |
sleep() { | |
return `${this.name} is going to sleep!`; | |
} |
View class-declaration.js
// ES6 style | |
class Animal { | |
constructor(name, weight) { | |
this.name = name; | |
this.weight = weight; | |
} | |
//... | |
} | |
// Check Type of ES6 class |
View ES5.js
function Animal(name, weight) { | |
this.name = name; | |
this.weight = weight; | |
} | |
Animal.prototype.eat = function() { | |
return `${this.name} is eating!`; | |
} | |
Animal.prototype.sleep = function() { |
View ES6.js
class Animal { | |
constructor(name, weight) { | |
this.name = name; | |
this.weight = weight; | |
} | |
eat() { | |
return `${this.name} is eating!`; | |
} |