美文网首页
for...in和Object.keys区别

for...in和Object.keys区别

作者: 吴晗君 | 来源:发表于2019-06-01 11:03 被阅读0次
function Parent () {}
Parent.prototype.x = 1
const child = new Parent()

// []
Object.keys(child)
// 'x'
for (let k in child) {
  console.log(k)
}

// configurable: true
// enumerable: true
// value: 1
// writable: true
Object.getOwnPropertyDescriptor(Parent.prototype, 'x')

相关文章

网友评论

      本文标题:for...in和Object.keys区别

      本文链接:https://www.haomeiwen.com/subject/gnpotctx.html