【发布时间】:2019-05-17 22:16:03
【问题描述】:
除此方法外,我如何从对象中删除原型字段?
const input = {foo: 'bar', __proto__: {unwanted: 'things'}}
expect(JSON.parse(JSON.stringify(input))).toEqual({foo: 'bar'}) // true
// this works but is there a cleaner way ?
【问题讨论】:
-
删除对象的
__proto__绝不是一个好主意。它具有使其成为对象的所有属性,您应该考虑使用hasOwnProperty
标签: javascript json ecmascript-6