mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.82k stars 1.98k forks source link

Fixes second for loop to use var i instead of var j #1052

Open jamesongamble opened 9 years ago

jamesongamble commented 9 years ago

The second for loop in this example script reinitializes the variable i. Weird looping bugs may arise later with bigger arrays. As such, I have set the second loop to start at var j.

Before:

screen shot 2015-02-19 at 4 49 01 pm

After:

screen shot 2015-02-19 at 4 48 42 pm

6pac commented 9 years ago

Not sure I follow. While it is true that these i instances are in the same scope, and the second one strictly does not need to be declared, what can be the problem if it's initialised ?

The place this kind of thing might cause problems is in reentrant code using a parent scope variable, or where the var keyword is forgotten and a global i is declared, which can definitely be unexpectedly changed at random times elsewhere. This case is neither of those.