August 2016
Intermediate to advanced
635 pages
14h 5m
English
One of the niceties of objects is that they can be built upon to create increasingly complex objects. This is a common pattern, which is used for any number of things. There is no inheritance in JavaScript because of its prototypical nature. However, you can combine functions from one prototype into another.
Let's say that we have a base class called Castle and we want to customize it into a more specific class called Winterfell. We can do so by first copying all of the properties from the Castle prototype onto the Winterfell prototype. This can be done like so:
let Castle = function(){}; Castle.prototype.build = function(){console.log("Castle built");} let Winterfell = function(){}; Winterfell.prototype.build = Castle.prototype.build; ...