Prototype (class library)
Prototype | |
---|---|
Basic data
|
|
developer | Sam Stephenson |
Current version | 1.7.3 (September 22, 2015) |
operating system | platform independent |
programming language | JavaScript |
category | JavaScript - Class Library |
License | MIT license |
prototypejs.org |
Prototype is a free , extensive JavaScript - class library , which was developed by Sam Stephenson in of 2005. It provides various programming aids for Ajax as well as possibilities to shorten the JavaScript source code. It was created in the context of Ruby on Rails and was an integral part of it up to version 3.1. Prototype now serves as the basis for numerous projects such as script.aculo.us and Rico .
Functions
Prototype provides many functions for developing JavaScripts. This ranges from shortcuts to more complex functions such as B. the one for XMLHttpRequest .
Functional examples
The $ () function
To get access to a DOM element of an HTML page, this function is usually used:
document.getElementById("id_des_elements")
The $()
function of Prototype also supplies DOM elements via IDs, but extends the returned elements with useful functions:
$("id_des_elements")
To z. B. to change the text color:
$("id_des_elements").setStyle({color: '#ffffff'});
The $ F () function
Means $F()
to obtain the value of a form element. In the case of a text field, the function returns the data in the field; for a Select object (dropdown menu) the currently selected entry.
$F("id_of_input_element")
The Ajax object
The Ajax object offers browser independent support for XMLHttpRequest
.
The following two types of retrieval are available:
Ajax.Request
delivers the raw server response; Ajax.Updater
writes the server response directly to a specified DOM object.
The Ajax.Request
call in the following example first reads the values from the form text fields, calls up a website from the web server, with the form data being sent as post values, and finally calls the defined function showResponse()
as soon as the request has been completed:
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: showResponse
});
object oriented programing
Prototype offers support for classic object-oriented programming.
The method Class.create()
in the following example creates a new class:
var FirstClass = Class.create({
// Die Methode "initialize" dient als Konstruktor
initialize: function () {
this.data = "Hello World";
}
});
var DataWriter = Class.create(FirstClass, {
printData: function () {
document.write(this.data);
}
});
Individual evidence
- ↑ Prototype Core Team: Download Prototype. September 22, 2015, accessed January 13, 2017 .
Web links
- Official website (English)
- Developer Notes for prototype.js refers to the outdated version 1.5.0 (English)