SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 82 | Next

Robin Pars, Laurence Moroney, and John Grieb

"Foundations of ASP.NET AJAX"

Next, the class Car is implemented using the prototype
model. In the prototype model, a class consists of two parts: the constructor, which
initializes the private variables, and the prototype, which is used to declare the methods
of the class and the dispose function in which you can perform any cleanup before your
object is reclaimed. It is important to note that in the prototype model, the notion of private
is handled by using variables that are prefixed with the underscore (_) character.
Finally, the class is registered to the namespace using the AJAXBook.Car.registerClass
method, which, in this case, takes a single parameter: the fully qualified name of the
class. Now any JavaScript that includes this JavaScript file will be able to create an
instance of an AJAXBook.Car object by using script such as the following:
var testCar = new AJAXBook.Car('Honda', 'Pilot', '2005');
Your code can then invoke methods on this object in the usual manner:
alert(testCar.get_Year());
Using Inheritance in JavaScript
In the previous section, you registered your class using the registerClass method prototype
that accepts only a single parameter.


Pages:
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94