for...in和Object.keys区别

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区别)