为什么不能删除此可配置属性? [英] Why is this configurable property not deletable?

查看:173
本文介绍了为什么不能删除此可配置属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可配置的属性似乎是可删除的:

Configurable properties seem to be deletable:

var o = {};
Object.defineProperty(o, 'prop', {
    configurable: true,
    value: 'val'
});
delete o.prop; // true
o.prop;        // undefined

但是在以下情况下,至少在Firefox和Chrome上它不起作用:

But it doesn't work in the following case, at least on Firefox and Chrome:

var form = document.createElement('form'),
    input = document.createElement('input');
form.appendChild(input);
var elems = form.elements;
Object.getOwnPropertyDescriptor(form, 0)
      .configurable; // true <────────────────────── !!!
delete elems[0];     // false                         │
elems[0];            // input                         │
(function(){ 'use strict'; //                         V
    delete elems[0]; // TypeError: property 0 is non-configurable
})();                // and can't be deleted

但这似乎与规范相矛盾.

But this seems to contradict the spec.

delete运算符的定义如下:

11.4.1-删除运算符

生产 UnaryExpression :delete UnaryExpression 是 评估如下:

The production UnaryExpression : delete UnaryExpression is evaluated as follows:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆