ImitationSportsCar.registerClass(
"AJAXBook.ImitationSportsCar",
AJAXBook.Car);
CHAPTER 3 ?– THE MICROSOFT AJAX LIBRARY: MAKING CLIENT-SIDE JAVASCRIPT EASIER 47
Within your client-side JavaScript, you can check whether or not your class implements
the IStickShift interface so that you can determine what kind of car it is and
whether or not it implements the interface??™s methods prior to using them.
The following example uses the web page from earlier but changes the content of the
button??™s onclick event handler to this:
function Button1_onclick()
{
var testSportsCar = new AJAXBook.SportsCar('Porsche','999','2005','6');
var testImitationSportsCar = new AJAXBook.ImitationSportsCar('Shorspe',
'123',
'2005');
ProcessCar(testSportsCar);
ProcessCar(testImitationSportsCar);
return false;
}
This event handler calls a helper function named ProcessCar, which looks like this:
function ProcessCar(theCar)
{
if(AJAXBook.IStickShift.isImplementedBy(theCar))
{
alert("Current Car: "
+ theCar.get_MakeandModel()
+ " This is a good sports car "
+ " -- I can change gears with a stick shift.
Pages:
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101