You can also include a second parameter that
specifies the base class from which the class is inheriting. One of the goals of AJAX is to
make your JavaScript easier to read and debug. Inheritance is a useful way to prevent
replication of member variables and methods among your classes, thereby helping you
to achieve this goal.
This is probably best demonstrated by example. Earlier you created a Car class for a
generic car. Lots of different types of cars exist; for example, a sport utility vehicle (SUV)
is different from a sports car in that it will usually have four-wheel drive (4WD), whereas
the sports car will have only two-wheel drive. If you want to implement car classes where
you will query if the car has the 4WD, it makes sense to have a subclass of Car called SUV
that has a 4WD property.
You can try this by adding the following code to the bottom of the JavaScript file you
created earlier:
AJAXBook.SUV = function(strMake, strModel, strYear, strDriveType)
{
AJAXBook.SUV.initializeBase(this, [strMake, strModel, strYear]);
this._DriveType = strDriveType;
}
CHAPTER 3 ?– THE MICROSOFT AJAX LIBRARY: MAKING CLIENT-SIDE JAVASCRIPT EASIER 43
AJAXBook.
Pages:
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95