Inheritance by constructor
Yehuda and Tomer Shiran describe in their WebReference.com article "Object-Oriented Programming with JavaScript, Part I: Inheritance an approach where properties and methods are immediate properties of each instance; a reference to the parent class constructor is maintained in each object; and inheritance is accomplished via calling the parent class's constructor as in:
Advantages
-
Clearly identifies parent class.
-
Easy initialization of properties inherited from parent class.
Disadvantages
-
No prototype properties used - increases storage since all properties and methods are immediate properties and none are shared amongst instances.
-
Must be constructed in full each time.
-
Does not allow easy access to methods of a parent class.
-
Does not indicate inheritance via the
instanceof
operator.
The simple approach using object constructors to inherit properties from parent classes does not meet the goals originally set for xbObject. However, the approach of maintaining a reference to the parent class's constructor merits further consideration.