在线文档教程

Reflect.deleteProperty

Reflect.deleteProperty

静态方法 Reflect.deleteProperty()允许用于删除属性。它很像deleteoperator,但它是一个函数。

语法

Reflect.deleteProperty(target, propertyKey)

参数

target删除属性的目标对象。propertyKey将被删除的属性的名称。

返回值

Boolean值表明该属性是否被成功删除。

异常

抛出一个TypeError,如果目标不是 Object

描述

Reflect.deleteProperty允许你删除一个对象上的属性。返回一个Boolean值表示该属性是否被成功删除。它几乎与非严格的deleteoperator 相同。

示例

使用Reflect.deleteProperty()

var obj = { x: 1, y: 2 }; Reflect.deleteProperty(obj, 'x' // true obj; // { y: 2 } var arr = [1, 2, 3, 4, 5]; Reflect.deleteProperty(arr, '3' // true arr; // [1, 2, 3, , 5] // Returns true if no such property exists Reflect.deleteProperty{}, 'foo' // true // Returns false if a property is unconfigurable Reflect.deleteProperty(Object.freeze{foo: 1}), 'foo' // false

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Reflect.deleteProperty' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Reflect.deleteProperty' in that specification.Draft

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support49(Yes)42 (42)No supportNo support10

FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo support49(Yes)42.0 (42)No supportNo support10