Prototype framework: dollar symbol $ Usage Analysis, prototype framework

Source: Internet
Author: User

Prototype framework: dollar symbol $ Usage Analysis, prototype framework

The example in this article describes the usage of the prototype Framework's $. We will share this with you for your reference. The details are as follows:

Prototype is an important tool for implementing object-oriented programming and a good javascript framework.
Anyone who uses jquery knows that jquery also has the $ dollar symbol. In prototype, there are also $. What are their differences.

1. Usage of $ () in prototype

Prototype $ ("test") or $ ("# test"), which is equivalent to document. getElementById ("test") in js ");
Jqueryp $ ("# test"), which is also equivalent to document. getElementById ("test") in js ");

2. $ () usage in prototype

Jquery $ ("div"), which is equivalent to document. getElementsByTagName ('div ')
If prototype also wants to retrieve all div elements on the page, it cannot be written like this.
Prototype $ ("div"), which is equivalent to document. getElementById ("div ")
Prototype $ ("div"), which is equivalent to document. getElementsByTagName ('div ')
Prototype syntax $ ("input [value = tank]") gets the tag whose input box value is tank on the page, which is similar to jquery but only has a $ symbol.

3. $ A () usage in prototype

$ A is mainly used to convert any set that can be used as an Array (such as NodeList, HTMLCollection returned by many DOM methods, or arguments attribute of function objects) into A real Array object. The following four methods can hide the div tag in the page:

$ A ($ ('div ')). each (Element. hide); $ A ($ ('div ')). map (Element. extend ). invoke ("hide"); // in terms of ideology, I often use $ A ($ ('div ') when using jquery ')). each (function (name, index) {name. style. display = 'none'; alert (name. innerHTML) ;}) $ A ($ ('div ')). each (function (name, index) {$ (name ). hide ();})

If TypeError: element. style is undefined {message = "element. style is undefined", more...} appears in the example, upgrade your prototype version to a lower level.

4. $ F () usage in prototype

I personally think that the usage of $ F is designed to take form data more conveniently, but it is relatively simple, because it can only be retrieved by ID

<Input name = "name" value = "tank" id = "name">
$ F ("name") is correct

<Input name = "name" value = "tank">
$ F ("name") is incorrect. TypeError: element is null {message = "element is null", more ...}

5. $ H () usage in prototype

When you pass in an object as a function parameter, $ H will input a prototype-specific hash object. $ H is like a converter, which can change the situation

$H({name:'tank',sex:1,height:'170cm'}).toArray()[["name", "tank"], ["sex", 1], ["height", "170cm"]]$H({name:'tank',sex:1,height:'170cm'}).toQueryString()"name=tank&sex=1&height=170cm"

6. $ R () usage in prototype

$ The R function and the original constructor have the same parameters: start and end indicate the lower and upper limits respectively (the types of the two parameters must be the same ), exclusive indicates whether to exclude the upper limit (the end parameter ). The upper limit is not excluded by default.

$ R instances describe a series of values that follow certain rule changes, such as numbers, text, or other types that support adjacent value derivation in semantics.

It is easy to remember.

$ A ($ R ("a", "z", true )). join (',') // Add the parameter true "a, B, c, d, e, f, g, h, I, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y "$ A ($ R (" a "," z ")). join (',') // No "a, B, c, d, e, f, g, h, I, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z"

$ R according to the rule, A $ R object is inferred. $ A converts the object to an array and converts the array to A string with A number.

$ R (0, 10 ). each (function (value) {alert (value * value) ;}); // The result is the same as the preceding one, but the each interpretation is different. $ A ($ R (0, 10). each (function (value) {alert (value * value );});

If this error is reported, TypeError: value. succ is not a function {message = "value. succ is not a function", more...}. Please upgrade

7. $ w () usage in prototype

$ W converts a string with spaces as the separator into an array. The explode ("", $ string) of the root php has the same function and is highly targeted.

$ W ("aa bb"). join (',')

If this error is reported, ReferenceError: $ w is not defined {message = "$ w is not defined", more...}. Please upgrade

I hope this article will help you design JavaScript programs.

Articles you may be interested in:
  • Prototype framework details
  • Detailed comparison between jquery and prototype frameworks
  • Differences between JQuery, Extjs, YUI, Prototype, and Dojo JS frameworks and brief descriptions of application scenarios
  • Scroll down to the latest topic of classic [prototype framework]

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.