Here are some tips I've summed up, just for reference.
The following code is basically in the jquery source can be seen, if the wrong place, please point out.
Use the source method as much as possible
JavaScript is an explanatory language and is slower to execute than a compiled language. The way the browser has been implemented, don't go through it again. In addition, the browser has implemented a number of methods in the algorithm has done a lot of optimization.
Avoid global lookups
In a function, a global object is stored as a local variable to reduce the global lookup because accessing the local variable is faster than accessing the global variable.
Try to reduce the number of cycles
Less than one cycle, you can improve the performance of several times. If you want to do multiple operations on each element of an array, use a loop as many times as possible, instead of looping multiple times, one operation at a time. In particular, when multiple regular matches are made, the regular expressions are merged as much as possible, and the corresponding matches are found as much as possible in one traversal.
Cycle
Switch
Conditional Branch
Arrange conditional branches, in probability order from high to Low: you can reduce the number of times the interpreter has probed the condition.
When >2 conditional branching in the same condition, the efficiency of using switch over If:switch branch selection is higher than if, especially in IE. 4 branch of the test, ie under the switch execution time is about half of if.
Replaces the conditional branch with the three-mesh operator.
Timer
If you are running code, you should not use settimeout instead of setinterval, because settimeout Initializes a timer every time, and setinterval only Initializes a timer at the beginning. Timer
Another way to create objects-don't use new
Use Boolean types whenever possible for a variable used as a marker
Mark with true and false directly, not with numbers or 1 and 0来 of strings.