除了通过此方法之外,如何从对象中删除原型(prototype)字段?
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 ?
最佳答案
这取决于您要实现的目标,但我通常建议使用 .hasOwnProperty
来检查该字段是否为原型(prototype)字段
引用:MDN
关于javascript - 如何从对象中删除原型(prototype)字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53817050/