chuanxshi / javascript-patterns

JavaScript Design Patterns
http://shichuan.github.io/javascript-patterns
9.39k stars 1.7k forks source link

Count down to zero #139

Open ehpc opened 9 years ago

ehpc commented 9 years ago

It is kind of unclear why counting down and while (https://github.com/shichuan/javascript-patterns/blob/master/general-patterns/for-loops.html) are preferred patterns, because modern browsers preoptimize these constructs. Maybe it will be a good idea to include some jsperf test, for example http://jsperf.com/for-vs-foreach/219.

gianlucascoccia commented 9 years ago

I'd like to add that semantically the preferred pattern is not the same as the others, sometimes the order in which you visit the array matters. Maybe add a comment to explain it?