Home >Web Front-end >JS Tutorial >prototype1.5 first experience_prototype
I have never had time to look at the prototype. Now it’s good. It has been updated to 1.5 pre1. Haha, I have to learn the powerful functions. This is another shortcut to improve my JS ability.
1. What is Prototype?
Maybe you haven’t used it yet, prototype.js is a JavaScript package written by Sam Stephenson. This wonderfully conceived, well-written, standards-compliant piece of code will shoulder the burden of creating thick-client, highly interactive web applications. Easily add Web 2.0 features.
If you have experienced this package recently, you will most likely find that documentation is not one of its strong points. Like all developers before me, I just dived into the prototype.js source code and experimented with every piece of it. I thought it would be nice to take notes as I studied him and share them with others.
I have also provided an unofficial reference for this package's objects, classes, methods and extensions.
2. Universal methods
This package contains many predefined objects and universal methods. The obvious purpose of writing these methods is to save you a lot of repetitive coding and idioms.
Starting from Prototype 1.5.x version, you can more conveniently operate DOM objects as follows:
var ele = $("myelement");
ele. hide(); //Hide DOM object compared to the previous version var ele = $("myelement");
Element.hide(ele); //Hide DOM object
What are the benefits of such a change Woolen cloth? I think firstly, it is more object-oriented, and secondly, it will facilitate future code prompts in the IDE.
2.1. Use the $() method
The $() method is a convenient shorthand for the document.getElementById() method that is used too frequently in DOM, just like this DOM method, This method returns the element with the id passed in as the parameter.
This is better than the method in DOM. You can pass multiple ids as parameters and $() returns an Array object with all required elements. The following example will describe this to you.