对象的可配置属性和可写属性之间的区别 [英] Difference between Configurable and Writable attributes of an Object

查看:111
本文介绍了对象的可配置属性和可写属性之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了以下有关javascript,对象数据属性属性

I saw the following regarding javascript, object data property attributes

-可配置:指定是否可以删除或更改属性.

— 
Configurable: Specifies whether the property can be deleted or changed.

-可枚举:指定是否可以在for/in循环中返回该属性.

— Enumerable: Specifies whether the property can be returned in a for/in loop.

—可写:指定是否可以更改属性.

— Writable: Specifies whether the property can be changed.

可配置"和可写"在这里表示相同(是否可以更改属性),那么为什么我们需要两个单独的属性?

Here "Configurable" and "Writable" are representing the same (whether the property can be changed), then why do we need two separate attributes?

推荐答案

来自: http://ejohn.org/blog/ecmascript-5-objects-and-properties/

可写:如果为false,则无法更改属性的值.

Writable: If false, the value of the property can not be changed.

可配置:如果为false,则任何删除该属性或更改其属性(可写,可配置或可枚举)的尝试都将失败.

Configurable: If false, any attempts to delete the property or change its attributes (Writable, Configurable, or Enumerable) will fail.

可枚举:如果为true,则当用户使用(obj中的var prop){}(或类似名称)时,将迭代该属性.

Enumerable: If true, the property will be iterated over when a user does for (var prop in obj){} (or similar).

这篇关于对象的可配置属性和可写属性之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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