javascript - 如何从对象中删除原型字段?
问题描述
除了通过此方法之外,我如何从对象中删除原型字段?
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
检查该字段是否为原型字段
参考:MDN
推荐阅读
- javascript - NodeJS:等待所有带有 Promises 的 foreach 完成,但从未真正完成
- javascript - Ctrl-Z/Y 使浏览器专注于最近更改的输入
- javascript - Google Cloud Functions - 通过 SSL 连接到 Cloud SQL
- microsoft-graph-api - 如何跨多个用户同步日历事件
- sql - 我的子查询返回多个值,我得到错误
- ruby-on-rails - 只处理带有载波的原始文件
- reactjs - 如何在我的应用程序中调试我的反应库?
- angular - 删除 @types/jest 后如何使用 jest.mock (^jest@24)
- java - 这个“R”在 Java 调试器中是什么意思?
- c# - 使用 c# 在远程 ssh 服务器上启动脚本