我想要做的是将代码中的每个警报更改为自定义警报(“您使用过警报”);
var hardCodedAlert = alert; //I know this won't work.But what to do ?
window.alert=function(){
if(this.count == undefined)
this.count=0;
this.count=this.count+1;
if(this.count == 1)
hardCodedAlert("You used alert");
};
最佳答案
是的,你可以这样做(例如):
var oldalert = window.alert;
window.alert= function alert(t){
alert.count = !alert.count ? 1 : alert.count + 1;
oldalert(t+' - That\'s alert nr '+alert.count);
};
关于javascript - 有没有办法克隆 javascript 中的 native 函数,例如 window.alert 或 document.write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10266825/