Prototype1.5 related knowledge and others' note _ prototype
Source: Internet
Author: User
Prototype1.5 related knowledge and others' notes have never had time to read prototype. Now it is ready and has been updated to 1.5 pre1, this is another shortcut to improve your JS capabilities.
1. What is Prototype?
Maybe you haven't used it. prototype. js is a JavaScript package written by Sam Stevenson. This fantastic idea of writing a piece of code that is compatible with standards will bear the burden of creating fat clients and highly interactive WEB applications. Web 2.0 features can be easily added.
If you have recently experienced this package, you may find that the document is not one of its strengths. Like all the developers before me, I can only drag them into the source code of prototype. js and test each part of it. I think it will be nice to take notes when I study him and share it with others.
I also provided unofficial references for the objects, classes, methods, and extensions of this package.
2. Universal Methods
This package contains many predefined objects and universal methods. The obvious purpose of writing these methods is to reduce your repeated coding and usage.
Starting with Prototype1.5.x, you can operate DOM objects more conveniently as you do in the following code:
Program code
Var ele = $ ("myelement ");
Ele. hide (); // hide the DOM object compared to the previous version var ele =$ ("myelement ");
Element. hide (ele); // hide a DOM object
What are the benefits of such a change? I think it is more object-oriented, and the second is to facilitate code prompts In the IDE in the future.
2.1. Use the $ () method
$ () Is a document that is used too frequently in the DOM. A convenient shorthand for the getElementById () method. Like this DOM method, this method returns the element of the id passed in by the parameter.
This is better than the DOM method. You can input multiple IDS as parameters and then $ () returns an Array object with all the required elements. The following example will describe this to you.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service