Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Implementation of traditional prototypal inheritance model, including ability to call superclass methods. |
Overview
While Javascript uses a prototypal inheritance model internally, it's generally too cumbersome for script authors to use in their scripts. It's a shame, because prototypal inheritance has no impact on object instantiation performance. Unlike "extends" approaches that developers sometimes use, prototypal inheritance also has the benefit of being able to add new methods and properties to instantiated objects by changing the superclass prototype.
To make prototypal inheritance more accessible and easier to work with, the Util API provides two functions:
- function.inherit() – inherit a superclass on to your class
- object.super() – an easy way to call methods on the superclass, or the superclass constructor
Objects that use prototypal inheritance are instantiated as usual, using the new operator.
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
|
Div | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Inheritance ModelTopics:
|