We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

handler.deleteProperty() 方法用于拦截对对象属性的 delete 操作。

语法

var p = new Proxy(target, {
  deleteProperty: function(target, property) {
  }
});

参数

deleteProperty 方法将会接受以下参数。 this 被绑定在 handler上。

target
目标对象。
property
待删除的属性名。

返回值

deleteProperty 必须返回一个 Boolean 类型的值,表示了该属性是否被成功删除。

描述

handler.deleteProperty() 方法可以拦截 delete 操作。

拦截

该方法会拦截以下操作:

不变量

如果违背了以下不变量,proxy 将会抛出一个 TypeError:

  • 如果目标对象的属性是不可配置的,那么该属性不能被删除。

示例

以下代码演示了对 delete 操作的拦截。

var p = new Proxy({}, {
  deleteProperty: function(target, prop) {
    console.log('called: ' + prop);
    return true;
  }
});

delete p.a; // "called: a"

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
[[Delete]]
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
[[Delete]]
Draft  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 18 (18) ? ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? 18.0 (18) ? ? ?

另见

文档标签和贡献者

此页面的贡献者: Illyrix
最后编辑者: Illyrix,