See this article, turn around first. From: http://ued.ctrip.com/blog/javascript-code-performance-optimization-summary.html
The following code is basically in the jquery source code inside can see, if have said wrong place, please point out.
Use the source method as much as possible
JavaScript is an explanatory language that is slower to execute than a compiled language. The way the browser has been implemented, do not implement it again. In addition, the methods that the browser has implemented have done a lot of optimizations in terms of algorithms.
Avoid global lookups
Global objects are stored as local variables in a function to reduce global lookups, because accessing local variables is faster than accessing global variables.
Minimize cycle times
A few loops, you can improve the performance of several times. If you want to perform multiple operations on each element of an array, use a loop as much as possible, multiple operations instead of multiple loops, one operation at a time. In particular, when making multiple regular matches, merge the regular expressions as much as possible and find the corresponding matches in a single traversal.
Cycle
Switch
Conditional Branch
Arrange conditional branching from high to low in order of probability: You can reduce the number of times the interpreter detects a condition.
In the same condition >2 conditional branching, using switch better than If:switch branch selection is more efficient than if, especially in IE. 4 branches of the test, ie under switch execution time is about half the IF.
Use the three-mesh operator to override conditional branching.
Timer
If you are targeting code that is constantly running, you should not use settimeout, but should be using setinterval, because settimeout Initializes a timer every time, and setinterval Initializes a timer at the beginning.
Another way to create an object-not using new
Variables used as tokens use Boolean types whenever possible
Mark directly with true and false, and do not use numbers or 1 of the string to mark.
JavaScript Code Performance Optimization Summary "Go"