js オブジェクトを学習するために小さなランダム シーケンス コンパレーターを作成しています。無限ループで、どこが間違っているのか誰か教えてもらえますか?
問題の2つの方法:
compareSequences: function() {
var instance = this;
var i = 0;
for( i; i <= limit; i++ ) {
console.log('Limit inside loop:', limit);
if( stacks.randomSequence[i] != stacks.userSequence[i] ) {
instance.errorMessage();
return;
}
if( i === limit ) {
instance.completeMessage();
}
console.log('Limit now', limit);
}
},
completeMessage: function() {
var instance = this;
alert('Well done you where right!');
limit = 5; //currently set as test, changing to ++ results in infinite loop
instance.selectors.startButton.removeAttr('disabled');
overallScore++;
instance.selectors.scoreCounter.html(overallScore);
},
私のフィドルへのリンク: http://jsfiddle.net/FNd79/22/