왜이 코드에서 저장 개체의 마지막 요소를 삭제하기 전에 먼저 감소 했습니까? 이렇게하면 마지막 요소가 아닌 두 번째 마지막 요소가 삭제되지 않습니까?이 코드에서 왜 감소 했습니까?
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;
}
}
}
그래서이 수를 0으로 초기화하여이 효과를 중화시킬 수 있습니다. –