Summary of Mobile Code specification (i.)

Source: Internet
Author: User

1, JS in the scope of use strict only valid in the current script: for example, 1.js inside call 2.js method, 1.js inside declare "use strict", and 2.js inside no declaration, then the call is Normal mode call, not strict mode;

2, Location.replace and location.href difference is not to destroy the previous page fallback function;

3, due to the browser for cross-domain restrictions, JS can not save the cross-domain picture (base64 not get the picture);

4, set and get disable, checked, selected and other attributes, please use the recommended prop method to replace the attr method (note: Some browsers through attr ("Checked", "checked");

5, for each function, return true is equal to continue, return false equal to break;

6, for the name of the page should not contain capital letters, eg. Isnotallowed.html (Note: Some browsers do not recognize uppercase letters);

7, the data method in jquery and zepto inside the implementation of the form is not the same.

The data method stored in jquery is saved by jquery itself. JQ also acquires a data-* of data, but the subsequent processing is done in the JQ object and will not be reflected in HTML.

Zepto the data stored in this method will be written to the data-* of the element itself. When you get a property value that begins with data-*, use $ (...). The data (*) function.

Native JS gets when the attribute name is removed data-, and then into a small hump form, that is, the previous value should be used Dom.dataset.someValue to obtain. The reverse is the same, which is set by Dom.dataset.someName

Data-some-name= "XX" on the HTML.

In addition,the naming rules of data-* should be in all lowercase, using "-", such as data-some-value= "", according to the specification.

8, in for...in ... In the loop, it is best to use the hasOwnProperty function to determine whether the property is a real attribute, lest the invalid value be processed;

9, if a DOM node is repeatedly used in the same function, you can manually cache this value, to avoid multiple lookups of the DOM tree. For example, var a = $ (body);

10, when using the Date object to generate instances, you should pay attention to the use of standard notation, or some browsers will error. Do not get used to the new Date ("Yyyy-mm-dd HH:mm:SS") because this format is not a standard format.

However, the current WebKit is supported. Long warn't, if later encountered other browser error or WebKit give up this support, convenient to find the reason;

11, because JS does not have block-level scope, so if the if and else blocks are used in the Var I as a counter, it is possible to report duplicate definitions of errors;

12, about variable declaration, var a=b=0; equivalent to var A; A= b; B = 0;b becomes a global variable;

13. The Declaration of the variable key in the for (var key in str) is the same as the declaration outside the for, because the variable declaration is advanced to the front of the current scope;

Summary of Mobile Code specification (i.)

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.