A getter failing to delete itself
-
I ran across this snippet, a lazy getter for energy of creeps/structures/etc. However, whoever wrote it left out the second half of the lazy part, so it deletes itself without recreating the property. For some reason I cannot fathom, the property doesn't get deleted, so it's still there when I try to access it a second time. Why does that work?
Object.defineProperty(RoomObject.prototype, "energy", {
get: function () {
delete this.energy;
if (this.storeCapacity) {
return this.store.energy;
} else if (this.energyCapacity) {
return this.energy;
} else if (this.carryCapacity) {
return this.carry.energy;
} else {
return undefined;
}
},
configurable: true
});