【发布时间】:2011-10-31 18:09:39
【问题描述】:
var Assertion = function() {
return { "dummy": "data" };
}
Object.defineProperty(Object.prototype, 'should', {
set: function(){},
get: function(){
return new Assertion(this);
}
});
// Insert magic here.
// This needs to be false
console.log(({}).should === undefined);
我在 ES5 中有哪些选项可以撤消 defineProperty 调用?
请不要像Object.defineProperty = function() { } 这样愚蠢的建议。
以下Object.defineProperty(Object.prototype, 'should', {})
和Object.defineProperty(Object.prototype, 'should', { value: undefined })
在 V8 中抛出 Uncaught TypeError: Cannot redefine property: defineProperty
Object.defineProperty(Object.prototype, 'should', {
set: function() {},
get: function() { return undefined; }
});
delete Object.prototype.should 还有does not work
【问题讨论】:
标签: javascript google-chrome node.js defineproperty