8.6.1 Property Attributes

2010-04-18

Every property in the language has a set of boolean attributes. Since attributes are only used in the specification, not the language, this set is fixed. There are two sets of attributes, depending on the type of property. Note that the square brackets surrounding the name is actually how they are used in the spec. This is an easy way of recognizing that they are internal properties and that you (probably) cannot get their value directly from within the language.

Named data properties always have the following attributes:

Name: [[Value]]
Type: Any Ecmascript language type
Description: The value retrieved by reading the property

Name: [[Writable]]
Type: Boolean
Description: If false, changing [[Value]] by using [[Put]] will fail

Name: [[Enumerable]]
Type: Boolean
Description: If true, the property shows up in a for-in loop. Otherwise it will not.

Name: [[Configurable]]
Type: Boolean
Description: If false, deleting the property, changing it into an accessor type or changing any attribute other than [[Value]] will fail. So you can still change [[Value]] !

Named accessor properties have a slightly different set of attributes:

Name: [[Get]]
Type: Object or Undefined
Description: If the value is an object it must be a Function. When accessed, the internal [[Call]] method is called with empty arguments list. The returned value is the value returned for the property. Otherwise undefined is returned.

Name: [[Set]]
Type: Object or Undefined
Description: If the value is an object it must be a Function. When accessed, the internal [[Call]] method is called with one parameter; the value assigned to the property. This property may change the value for future gets. So putting 5 to an accessor property could still mean the property returns 4 immediately after setting it.

Name: [[Enumerable]]
Type: Boolean
Description: If true, the property shows up in a for-in loop. Otherwise it will not.

Name: [[Configurable]]
Type: Boolean
Description: If false, deleting the property, changing it into a data type or changing any attribute will fail. So unlike with data properties, you cannot change [[Put]] and [[Set]] for accessor properties.

Unless specified otherwise, the default attribute values are as follows:

[[Value]] : undefined
[[Get]] : undefined
[[Set]] : undefined
[[Writable]] : false
[[Enumerable]] : false
[[Configurable]] : false

So by default, properties are pretty immutable ;) But most properties have custom values, so don't worry.