在线文档教程

Proxy.handler.deleteProperty

Proxy.handler.deleteProperty

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

语法

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

参数

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

target目标对象。

返回值

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

描述

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

拦截

该方法会拦截以下操作:

  • Property deletion: delete proxy[foo] and delete proxy.foo

  • Reflect.deleteProperty()

不变量

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

  • A property cannot be deleted, if it exists as a non-configurable own property of the target object.ExamplesThe following code traps the delete operator.var p = new Proxy{}, {   deleteProperty: function(target, prop) {     if (prop in target){       delete target[prop]       console.log('property removed: ' + prop)       return true     }     else {       console.log('property not found: ' + prop)       return false     }   } }) var result p.a = 10 console.log('a' in p)  // true result = delete p.a    // "property removed: a" console.log(result)    // true console.log('a' in p)  // false result = delete p.a    // "property not found: a" console.log(result)    // falseSpecificationsSpecificationStatusCommentECMAScript 2015 (6th Edition, ECMA-262)The definition of '[Delete]' in that specification.StandardInitial definition.ECMAScript Latest Draft (ECMA-262)The definition of '[Delete]' in that specification.Draft​Browser compatibilityFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariBasic support?18 (18)???FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileBasic support??18.0 (18)???See also