私はたくさんのループをあらかじめ作成する必要があるページを作成しようとしています。 while/forループを使用すると、ループが完了するまでページが停止し、この場合ループが数時間実行される可能性があります。私もsetTimeoutを使用しようとしましたが、再帰の限界に達します。ページが再帰制限に達しないようにするにはどうすればよいですか?中にJavaScriptループを作成しないでください
var looper = {
characters: 'abcdefghijklmnopqrstuvwxyz',
current: [0],
target: '',
max: 25,
setHash: function(hash) {
this.target = hash;
this.max = this.characters.length;
},
getString: function() {
string = '';
for (letter in this.current) {
string += this.characters[this.current[letter]];
}
return string;
},
hash: function() {
return Sha1.hash(this.getString());
},
increment: function() {
this.current[0] += 1;
if (this.current[0] > this.max) {
if (this.current.length == 1) {
this.current = [0, 0];
} else {
this.current[1] += 1;
this.current[0] = 0;
}
}
if (this.current[1] > this.max) {
if (this.current.length == 2) {
this.current[2] == 0;
} else {
this.current[3] += 1;
this.current[2] = 0;
}
}
},
loop: function() {
if (this.hash() == this.target) {
alert(this.getString());
} else {
this.increment();
setTimeout(this.loop(), 1);
}
}
}
なぜこのような処理をクライアント側で行っていますか? –
@Karl Knechtel - Think Distributed – AJ00200