Prototype JavaScript Framework

Prototype is a free, extensive JavaScript class library that was developed by Sam Stephenson in 2005. We produce both different programming support for Ajax is available as well as ways to shorten the JavaScript source code. It arose in the context of Ruby on Rails and was up to version 3.1 its integral part. Meanwhile Prototype serves as the basis for numerous projects such as script.aculo.us and Rico.

Functions

Prototype provides many functions in the development of JavaScripts. This ranges from shortcuts (shortcuts ) to more complex functions such as the XMLHttpRequest.

Function Examples

The $ () function

To gain access to a DOM element of an HTML page, usually this function is applied:

Document.getElementById (" id_des_elements " ) The $ () function of Prototype also provides DOM elements on IDs, extended the returned items but still with useful features:

$ (" id_des_elements " ) For example, to change the text color:

$ (" id_des_elements " ) setStyle ( {color: '# ffffff '} );. The $ F () function

Using $ F ( ), we obtain the value of a form element. For a text box, the function returns the data already in the field; in a Select object the currently selected item (dropdown menu).

$ F ( " id_of_input_element " ) The Ajax object

The Ajax -Object provides independent support for XMLHttpRequest from the browser.

There are two ways for retrieval: Ajax.Request provides the raw server response; Ajax.Updater writes the server's response directly to a specified DOM object.

The Ajax.Request call in the following example first reads the values ​​from the form text fields from, retrieves a web page from the web server where the form data is sent as a post- values ​​and calls finally defined function show response () as soon as the request was done:

Var params = $ H ( { value1: $ F ( " ID_1 ") value2: $ F ( " ID_2 " ) });   var MyRequest = new Ajax.Request ( " http://www.example.com/server_script ", { method: "POST", parameters: params, onComplete: show response }); Object-Oriented Programming

Prototype provides support for classical object-oriented programming.

The method Class.create () in the following example creates a new class:

Var = Class.create First Class ({     / / The method " initialize " is used as a constructor     initialize: function () {         this.data = " Hello World";     } });   var DataWriter = Class.create ( First Class {      print data: function () {          document.write ( this.data );      } }); References

662955
de