The zInherit library adds two methods to the Object class: inheritFrom() and instanceOf().
The following line uses prototype chaining to inherit methods from BaseClass to SubClass:
SubClass.prototype = new BaseClass();
This line can be replaced with the following:
SubClass.prototype.inheritFrom(BaseClass);
The inheritFrom() method accepts the class from which to copy the methods.
The inheritFrom() method doesn't actually create a new instance of the class to inherit from.
The inheritFrom() method call must be used exactly where the prototype assignment normally occurs.
The instanceOf() method is a replacement for the instanceof operator.
Page title
This example defines a Friend
class and an Animal
class. Then, it defines a Dog
class that inherits from both.