如何从 javascript 类型中删除方法
我有一些在第 3 方网站上运行的 javascript,这需要我临时向数组类型添加一个函数,例如,
Array.prototype.foo = function() { alert("foo's for everyone!"); };
我想成为一名优秀的开发人员,并且尽可能不污染其他人代码的类型系统,所以一次不再需要该功能我想再次删除该功能。这可能吗?
I have a bit of javascript that runs on a 3rd party's website which requires me to temporarily add a function to the Array type, e.g.
Array.prototype.foo = function() { alert("foo's for everyone!"); };
I want to be a good developer and not pollute the type systems of other people's code as much as possible so once the function is no longer needed I want to remove the function again. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
delete
,这通常适用于从对象中删除所有类型的属性:示例:http ://jsbin.com/iyamut
MDN 文档:删除
You can use
delete
, which in general is good for removing all types of properties from objects:Example: http://jsbin.com/iyamut
MDN Documentation: delete
或者
or