Main Page

Summary

Rectangle.prototype.getArea = function () {
return this.length * this.width;
};
}
}
The main difference between this and the
Triangle
class (aside from the different
registerClass()
and
defineClass()
calls) is calling the superclass
init()
method with an argument of
4
. Other than
that, the additional
length
and
width
properties are added and the
getArea()
method is overridden.
Summary
This chapter introduced the concept of object inheritance in ECMAScript (and, therefore, in JavaScript)
using object masquerading and prototype chaining. You learned that using these methods together is the
optimal way to establish inheritance between classes.
Finally, a couple of alternate methods of establishing inheritance were introduced: zInherit and xbObjects.
These JavaScript libraries, available free on the Internet, introduce new and different capabilities for object
inheritance.
This wraps up the discussion of ECMAScript, the core of JavaScript. The following chapters build upon
this base and introduce you to more Web-specific aspects of the language.
124
Chapter 4
07_579088 ch04.qxd 3/28/05 11:36 AM Page 124


JavaScript EditorFree JavaScript Editor     Ajax Editor


©