Prototype Java Script Framework - Object-oriented Programming

Object-oriented Programming

Prototype also adds support for more traditional object-oriented programming. The Class.create method is used to create a new class. A class is then assigned a prototype which acts as a blueprint for instances of the class.

var FirstClass = Class.create( { // The initialize method serves as a constructor initialize: function { this.data = "Hello World"; } });

Extending another class:

Ajax.Request= Class.create( Ajax.Base, { //Override the initialize method initialize: function(url, options) { this.transport = Ajax.getTransport; this.setOptions(options); this.request(url); }, // ...more methods add ... });

The framework function Object.extend(dest, src) takes two objects as parameters and copies the properties of the second object to the first one simulating inheritance. The combined object is also returned as a result from the function. As in the example above, the first parameter usually creates the base object, while the second is an anonymous object used solely for defining additional properties. The entire sub-class declaration happens within the parentheses of the function call.

Read more about this topic:  Prototype Java Script Framework

Famous quotes containing the word programming:

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)