Reflections on "configurable" Attribute (JavaScript)

A JavaScript object is composed of properties which may fall into two categories—data properties and accessor properties. A property is identified by a name and described by four attributes. The attributes
used to describe a property are typically enclosed into a so called descriptor object.

  • Attributes describing data properties are value, writable,
    configurable, and enumerable
    .
  • Attributes describing accessor properties are getter, setter,
    configurable, and enumerable
    .

From the figure above, we can see that "configurabe" is shared by both categories.This article addresses some issues about this attribute and its subtle relation to "writable" in terms of data properties.

Typically, "configurable" constraints configurations we can perform on the underlying property, that is, whether or not can we change the attribute values. On the other hand, it also controls whether a property can be deleted. If
a property is not configurable, you can‘t change its configurable or enumerable attributes and you can‘t delete the property. Since the "configurable" is shared, our disscussion divides into two parts:

  I. data property

If the "configurable" attribute of a data property is false, you are prohibited from doing the following:

  • changing the "writable" attribute from false to true, but you can change it from true to false. (Enforcing restrictions of altering property value is acceptable.)
  • changing it to an accessor property.

Q: If a property is not writable, is its value locked down from any change?

A: It depends. If writable is false, you cannot alter the property value by assigning to object_name.property_name. However, if
configrable is true, you can always change the property value by calling Object.defineProperty() to configure the value attribute to the new one, even though assigning to object_name.property_name is
forbidden when writable is false. In a word, to lock down a property value, you have to make configurable and writable false at the same time.

   II. accessor property

If the "configurable" attribute of an accessor property is false, you are prohibited from doing the following:

  • changing the getter or setter method.
  • changing the underlying property to a data property

The above relections are personal thoughts based on 《JavaScript_The Definite Guide_Six-edition》.

Reflections on "configurable" Attribute (JavaScript)

时间: 2024-08-28 02:46:24

Reflections on "configurable" Attribute (JavaScript)的相关文章

《JavaScript权威指南》学习笔记 第三天 找个对象

现实生活中真的对象没有找到,在JavaScript 里左一个对象又一个对象,搞的我也是晕晕乎乎不知所云.人事复杂,人心难懂.我虽然是文科生,但是也不善于巧言.还是在js里面找找对象吧.那么我们今天就从js的对象开始入手. 昨天,我们讲过了js里面的数据类型分为两种,原始类型,对象类型.对象类型的组成又是由原始类型和对象类型共同组成的. 今天我们来了解一下对象的一些特征.使用对象无非是增(crate) .删(delete).改(set).查(query); 对象由键值对儿组成,那么对象的属性(ke

JavaScript面向对象学习——3

对象基础介绍: 1.对象是JavaScript的基本数据类型.在java中Object是所有对象的基类,在JavaScript中同样,Object是所有对象的基类,那么Object自身属性和方法在所有对象中都会体现,只是不同的类对方法有不同的重写. 2.JavaScript对象是动态的-可以新增属性也可以删除属性-但它们常用来模拟静态对象以及静态类型语言中的"结构体"(struct).有时它们也用做字符串的集合(忽略名/值对中的值). 3.除字符串.数字.true. false. nu

JavaScript Objiects and Prototypes

Create JavaScript Objects Using Object Literals: var obj = {name: 'Allen', color: 'White'}; Dynamic Nature of JavaScript: obj.age = 3; Using Constructor Functions: Using Object.create: Using ECMAScript6 Classes: JavaScript Object Properties: Using Br

JavaScript对象类型详解

JavaScript对象类型详解 JavaScrtip有六种数据类型,一种复杂的数据类型(引用类型),即Object对象类型,还有五种简单的数据类型(原始类型):Number.String.Boolean.Undefined和Null.其中,最核心的类型就是对象类型了.同时要注意,简单类型都是不可变的,而对象类型是可变的. 什么是对象 一个对象是一组简单数据类型(有时是引用数据类型)的无序列表,被存储为一系列的名-值对(name-value pairs).这个列表中的每一项被称为 属性(如果是函

第六章:Javascript对象

对象是javascript的基本数据类型.对象是一种复合值.它将很多值(原始值 或者其他对象)聚合在一起.可通过名字访问这些值.对象也可以看做是属性的无序集合,每个属性都有一个名/值.属性名是字符串,因此我们可以把对象看成是从字符串到值的映射.这种基本数据结构还有很多叫法,有些我们已经非常熟悉,比如“散列”(hash).“散列表”(hashtable).“字典”(dictionary).“关联数组”(assciativeArray).然而对象不仅仅是字符串到值的映射,除了可以保持的自有的属性,j

javascript 修改css样式

abc.css CSS code .class1     {    width:10px;    background-color: red;    } HTML code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><link rel="stylesheet" type="text/css" href

第6章 对象

<script type="text/javascript"> //对象JS的基本数据类型. //对象是一种复合值,它将很多值(原始值或者其他对象)聚合在一起,可通过名字访问这些值 //对象也可以看做是属性的无序集合,每个属性都是一个键/值对. //属性名是字符串,因此我们可以把对象看作是从字符串到值的映射 //这种基本数据结构还有很多种叫法 //散列(hash) //散列表(hashtable) //字典(dictionary) //关联数组(associative ar

WEB网页专业词汇 汇总

Accessibility  可访问性 accessor properties 存取器属性 addition 加法 aggregate 聚合 alphabetical order 字母表顺序 Anchor Element 锚元素 anchors 锚 Animation 动画 Arguments 参数/实参 Arguments and Parameters 实参和形参 arithmetic operations 算术运算 arithmetic operator 算术运算符 arity 参数个数 a

The window object

At the core of the BOM is the window object, which represents an instance of the browser. The window object serves a dual purpose in browsers, acting as the JavaScript interface to the browser window and the ECMAScript Global object. This means that