📅  最后修改于: 2020-10-25 09:14:10             🧑  作者: Mango
用于完全使用delete运算符删除属性的handler.deleteProperty()方法。如果删除成功,则此方法返回true。
deleteProperty: function(target, property)
目标:目标对象。
属性:要删除的属性的名称。
此方法返回一个布尔值。它指示属性是否成功删除。
Chrome | 49 |
Edge | 12 |
Firefox | 18 |
Opera | 36 |
var proxy = new Proxy({}, {
deleteProperty: function(target, prop) {
document.writeln("Called: " + prop);
return true;
//if sucessfullt delete,return true.
}
});delete proxy.abc;
输出:
Called: abc
var proxy = new Proxy({}, {
deleteProperty: function(target, name) {
document.write('In delete Property ');
return delete target[name];
}
});
delete proxy.foo;
document.writeln(proxy.name);
输出:
In delete Property undefined
var f = { bar: 'baz' }
f.bar = 'baz'
document.writeln('bar' in f)
delete f.bar
document.writeln('bar' in f)
var foo = { bar: 'baz' }
foo.bar = 'baz'
document.writeln('bar' in foo)
输出:
true false true