I am experiencing a funny issue with JavaScript. I have a feeling this could have something to do with Closures, which, I admit, I am not really comfortable with.
Problem It seems that calling a function from within results in a premature termination of the loop. I tried running the same loop without the function call and console.log() outputs the counter accurately suggesting the function call is breaking the loop.
Could someone suggest a possible fix? I have the code pasted here:
AbstractModel.prototype.deactivateContext = function(context){
for(i=0;i<this.asset.length;i++){
if(this.asset[i].context == context){
this.asset[i].deactivate();
console.log(i);
this.notify(this.asset[i],"REFRESHASSETS");
}
}
}
var. If the other function also uses "i" to control a loop, then you'll have problems.