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)