These are some of my experiences when writing code. I summarized them and shared them with you. There is no order. I just wrote them as I thought of them.
1. Use local variables to avoid using global variables
for example
Change to
The advantage of local variables is that it reduces the scope chain search. I recommend using local variables if there are two references.
2. Avoid using with (I guess everyone on earth knows this)
I understand that the reason is that with will create its own scope, which lengthens the original scope chain, making the code executed in the with block slower. It seems to save code in writing, but in fact, it becomes longer in access. It becomes cumbersome and performance degrades. Example
use with
In fact, it can be written as
3. How to traverse nodelist
The general method is
(Note: This method can be used in nodelist, but if you use it in array, there will be problems. If there is a 0 or null in the array, it will be blind)