JS - 可枚举性

对象的每个属性都有一个 descriptor,Object.getOwnPropertyDescriptor 方法可以获取属性的 descriptor,示例如下:

let obj = { foo: 123 };
Object.getOwnPropertyDescriptor(obj, 'foo')
//  {
//    value: 123,
//    writable: true,
//    enumerable: true,
//    configurable: true
//  }

有4个操作会忽略 enumerable 为 false 的属性,分别是 for...inObject.keys()Object.assign()JSON.stringify()
for...in 会遍历继承的属性

你可能感兴趣的:(JS - 可枚举性)