I learned from books that you should write for loop like this:
(我从书中了解到,您应该为循环编写这样的内容:)
for(var i=0, len=arr.length; i < len; i++){
// blah blah
}
so the arr.length
will not be calculated each time.
(因此不会每次都计算arr.length
。)
Others say that the compiler will do some optimization to this, so you can just write:
(其他人则说编译器会对此做一些优化,因此您可以编写:)
for(var i=0; i < arr.length; i++){
// blah blah
}
I just want to know which is the best way in practice?
(我只想知道哪种是最佳实践?)
ask by wong2 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…