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', {})
条
是not work吗
还有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