for accessibility. Problems can be solved through shortcut keys and other methods. This can better restore the semantics of HTML elements.
Simple for loop optimization
When you write a for loop, there is a very simple trick that can improve performance.
for ( var i = 0; i < elements. length; i )
Use the following statement instead of the above:
for ( var i = 0, j = elements.length; i < j; i )
This way you can store the number of elements (the value of elements.length) In a variable j, this eliminates the need to count the number of elements each time through the loop.
Use anonymous functions as event handlers
Especially for short functions, creating an anonymous function is more readable than using a reference to a named function .
anchor.onclick = function() { map.goToPosition( home ); return false; }
March: It is more efficient to use named functions when developing more complex JavaScript.
Use Array.join instead of concatenating strings
When concatenating many strings, variables, etc. into a long string, all Put strings and variables into an array, and then use the join method to form a long string, which is better than string concatenation in terms of code readability and performance.
var text = 'There are' elements.length 'members in the elements array.';
var text = ['There are', elements.length, 'members in the elements array.'].join(' ');