1 个回答

A property has a name and a value. A property name may be any string, including the empty string, but no object may have two properties with the same name. The value may be any JavaScript value, or (in ECMAScript 5) it may be a getter or a setter function (or both). In addition to its name and value, each property has associated values that we’ll call property attributes: writable attribute, enumerable attribute and configurable attribute

也就是说,对象的属性就是property,例如:

window.Infinity;    // Inifinity是window对象的property
var obj = {x: 1, y: 2};    // x, y都是obj对象的property

但是ES5中额外提供了一些东西去描述对象属性(property)的属性(attribute),即是 只读的(writable),可枚举的(enumerable),和可配置的(configurable)。
这些attributes的定义方式如:

var o = {};
Object.defineProperty(o, "x", {
    value : 1,
    writable: true,                 // o对象x属性(property)的writable属性(attribute)
    enumerable: false,              // o对象x属性(property)的enumerable属性(attribute)
    configurable: true              // o对象x属性(property)的configurable属性(attribute)
});

另外,还有Object attributes:

In addition to its properties, every object has three associated object attributes: prototype, class, extensible

(以上定义来自犀牛书)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏