The following block of code demonstrates Douglas Crockford's prototypal inheritance operator, in which the OldObject is added to the NewObject's prototype, inheriting all of it's public properties and methods. Keep in mind that with this pure prototypal pattern you are to use plain objects, not functions. No initialization needed.
Now that we've declared Vehicle, Motorcycle may inherit from it. Motorcycle's constructor contains a call to Vehicle's constructor through apply, and then adds any overrides or custom properties and functions thereafter. In this case, a motorcycle only has two wheels and one headlight.
For a deeper understanding of design patterns, Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Professional Computing Series) is the best book you could possibly own.
- You Don't Know JS: this & Object Prototypes
- Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Professional Computing Series)