なぜこのコードでは、ストレージオブジェクトの最後の要素を削除する前に、カウントが最初に減ったのですか? このようにして、lastの代わりに2番目の最後の要素を削除しませんか?なぜこのコードのカウントが減ったのですか?
var stack = function() {
this.count = 0;
this.storage = {};
this.push = function (value) {
this.storage[this.count] = value;
this.count++;
}
this.pop = function() {
if (this.count === 0) {
return undefined;
}
else {
this.count--;
var result = this.storage[this.count];
delete this.storage[this.count];
return result;
}
}
}
これはカウントがゼロに初期化されているため、この効果を中和できる理由です。 –