JavaScript中propertie和attribute的区别
PHPz
PHPz 2017-04-11 09:10:00
[JavaScript讨论组]

PHPz
PHPz

学习是最好的投资!

全部回复(1)
PHP中文网

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

(以上定义来自犀牛书)

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号