javascript - for-loop gets stuck on the same number -
below loop runs 1 time i=0, indefinitely i=1 browser crash, i.e. not increment:
cascadecomponent: function(item, fn, scope) { if (fn.call(scope || this, item) !== false) { if (item.items) { (i = 0; < item.items.items.length; i++) { this.cascadecomponent(item.items.items[i], fn, scope); } } } }
i can avoid issue using frameworks iteration loop. alternatively have same loop working slight difference array found in item.items vs. item.items.items.
any ideas why happens? it's same in chrome , firefox.
you using global i
variable. add together line @ start of function:
var i;
otherwise each recursive phone call resets i
0 invocations of cascadecomponent
.
javascript
No comments:
Post a Comment