Uber - access to the parent from a child object

Classical OO languages usually have a special syntax that gives you access to the parent class, also referred to the superclass. This could be convenient when a child wants to have a method that does everything the parent's method does, plus something in addition to it. In such cases, the child calls the parent's method with the same name and works with the result.

In JavaScript, there is no such special syntax, but it's trivial to achieve the same functionality. Let's rewrite the last example, and while taking care of inheritance, also create an uber property that points to the parent's prototype object:

 function Shape() {} // augment prototype Shape.prototype.name = 'Shape'; Shape.prototype.toString ...

Get Object-Oriented JavaScript - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.