淡い属性は、列挙できないことを意味します。非列挙性質が影響することに注意してくださいfor ... in
、Object.keys()
、JSON.stringify()
結果などを!
function Person() {
this.name = 'ifer';
}
Person.prototype.age = 18;
const p = new Person();
Object.defineProperty(p, 'sex', {
value: 'man', // 内容
writable: true, // 修改
configurable: true, // 删除
enumerable: false, // 枚举
});
console.log(p);
Object.getOwnPropertyDescriptor(p, 'name'); // 获取属性修饰符