ES8中禁止对象元素枚举

2019-11-11 张宇童 学习日志

let obj = {
    name: '小明',
    age: 18
}
Object.defineProperty(obj, 'age', {
    enumerable: false
})
 for (let i in obj) {
    console.log(i)
 }

console.log(Reflect.ownKeys(obj))
console.log(Object.keys(obj))
console.log(Object.getOwnPropertyDescriptors(obj))

标签: javascript ES6

发表评论:

Powered by emlog