Home  >  Article  >  Web Front-end  >  Detailed explanation of Prototype framework_javascript skills

Detailed explanation of Prototype framework_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:29:591495browse

The "Prototype" mentioned here is not the prototype ("prototype") in JavaScript programming, but a JavaScript class library written by "Sam Stephenson". This wonderfully conceived and standard-compatible class library can help programmers easily create rich client pages with highly interactive "web2.0" features.

•Many people’s first contact with Prototype begins with its “$” series of functions. These are similar to desktop application shortcuts and are the most frequently used set of functions in the Prototype framework. In addition, Prototype's support for Ajax is also of great interest to developers. Of course, Prototype's functions are not limited to this. It has extended a large number of JavaScript built-in objects and also defined many new objects.

Introduction to prototype framework:

•Prototype is currently the most widely used Ajax development framework. It is characterized by practical functions and small size, making it very suitable for use in small and medium-sized Web applications. Developing Ajax applications requires writing a large amount of client-side JavaScript scripts, and the Prototype framework can greatly simplify the writing of JavaScript code. What's even more rare is that Prototype has excellent features that are compatible with various browsers. Using this framework you don't have to consider browser compatibility issues.

•Prototype has made many useful extensions to JavaScript's built-in objects (such as "String" object, "Array" object, etc.). At the same time, many custom objects have been added to the framework, including those for Ajax development. Support, etc. are all implemented in custom objects. Prototype can help developers achieve the following goals:

•(1) Perform various processing on strings
•(2) Use enumeration to access collection objects
•(3) Perform common DOM operations in a simpler way
•(4) Use CSS selectors to locate page elements
•(5) Initiate an Ajax HTTP request and process the response
•(6) Monitor DOM events and process events

•Detailed explanation of “Prototype” framework functions—using practical functions

The implementation of the "Prototype" framework only contains one JavaScript. The file size of version 1.6 of "Prototype.js" is 127K bytes and about 4220 lines. The syntax applied in the page is similar to:

&#8226;<script type=”text/javascript” src=”inc"js"Prototype.js” ></script>

•You can then enjoy the convenience brought by this framework in subsequent scripts.

•There are many predefined objects and utility functions in this framework, which can free programmers from repetitive typing.

•(1) Use the “$()” function.
•(2) Use the “$F()” function. This function is another popular "shortcut" that can be used to return the value of any form input control, such as multi-line text boxes and drop-down list boxes. This method can also take an element id or the element itself as a parameter.
•(3) Use the “$A()” function. This function converts the single argument it receives into an Array object.
•(4) Use the “$H()” function. This function converts some objects into an enumerable Hash object similar to an associative array.
•(5) Use the “$R()” function. This function is the abbreviation of "new ObjectRange(lowBound,upperBound,excludeBounds)" and is used to create a range object.
•(6) Use the "Try.these()" function. The "Try.these()" method is used to call different methods until one of them succeeds. This function takes a series of methods as parameters and executes these methods one by one in order until one of them is executed successfully. Returns the return value of the successfully executed method. The "Try.these()" function can be used to handle compatibility issues.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn