Understanding these things is truly understanding JavaScript (1 ).

Source: Internet
Author: User

The following things are not what I have created. They are the essence of some books I think. After learning about JavaScript, I feel that my understanding of JavaScript has been further improved, find out something that is also known as a trick or a trick. I will apply this knowledge to a new framework. The goal of the new framework is to use js to display various charts. Although there are already many frameworks with this function, however, I think it is still necessary to create a report system, because my ultimate goal is to implement a report system. Haha !!!, Stay tuned. Now let's get down to the point where our JavaScript experts have something to learn. This item will be very long and may be released in a serialized manner.

  Dom related to browsers

Separation of focus: A web application consists of three parts: content (HTML), presentation (CSS), and behavior (JavaScript ). Use these three parts as much as possible when developing applications.

  Dom access

Minimize Dom access:

1. Avoid circular Dom access;

// Bad for (VAR I = 0; I <100; I + = 1) {document. getelementbyid ('result '). innerhtml + = I + ',';} // var I, content = ''; for (I = 0; I <100; I + = 1) {content + = I + ',';} document. getelementbyid ('result '). innerhtml + = content;

2. Use local variables to hold Dom references;

// Var padding = document. getelementbyid ('result '). style. padding, margin = document. getelementbyid ("result "). style. margin; // good var style = document. getelementbyid ('result '). style, padding = style. padding, margin = style. margin;

3. You can use the selector API;

Selector is available only in popular browsers. You can also use some class libraries, such as jquery

      document.querySelector("ul .selected");      document.querySelectorAll("#widget .class");

4. cache length when traversing HTML element sets;

  Dom operations

Document fragment may be used to add DOM nodes;

  Event

  Event proxy

  Long run script

Web workers

Run scripts remotely

Language:

Common Conversions

X + "" => string (X)

+ X => Number (X)

X-0 => Number (X)

!! X => Boolean (X)

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.