function secret(){
var HOP = Object.prototype.hasOwnProperty;
this.getHOP = function(){
return HOP;
}
}
new secret().getHOP(); //Will now be the copy of hasOwnProperty
//and nobody can modify it
//stupid script:
Object.prototype.hasOwnProperty = function () {
return !!'I am stupid';
};
//restore
Object.prototype.hasOwnProperty = new secret().getHOP(); //DONE.
更新
如果在加载每个脚本之前对其进行了修改,那么您可以这样做:
Object.prototype.hasOwnProperty = String.prototype.hasOwnProperty
他们是一样的。:D
还有更多内容可供您复制:
Boolean.prototype.hasOwnProperty
Number.prototype.hasOwnProperty
Function.prototype.hasOwnProperty
- ETC...
更新 2
恢复原始功能的新方法:
var win=window.open("about:blank");
win.close();
Object.prototype.hasOwnProperty = win.Object.prototype.hasOwnProperty;
有点骇人听闻。或者您可以创建一个隐藏的<iframe>
.
var win = document.createElement("iframe");
win.style.display = "none";
document.body.appendChild(win);
Object.prototype.hasOwnProperty = win.contentWindow.Object.prototype.hasOwnProperty;
document.body.removeChild(win);