October 2018
Intermediate to advanced
590 pages
15h 5m
English
In ES6, object literals support setting prototypes, shorthand assignments, defining methods, making super calls, and computing properties with expressions.
Let's see the following example, which creates an advisor object with a TeamMember object as its prototype:
1. const advice = 'Stay hungry. Stay foolish.';2. 3. let advisor = {4. __proto__: new TeamMember('Adam', ['Consulting']), 5. advice,6. greeting () {7. super.greeting();8. console.log(this.advice); 9. },10. [advice.split('.')[0]]: 'Always learn more'11. };
Line 4, assigning the object of TeamMember to the advisor object's __proto__ property makes advisor an instance of TeamMember:
console.log(TeamMember.prototype.isPrototypeOf(advisor)); // trueconsole.log(advisor ...
Read now
Unlock full access