很简单:我想禁用/覆盖alert()
.
我可以这样做吗?
更重要的是,这样做是否正确?
严格模式呢?
是的,您可以禁用或覆盖alert()
. 不,这样做是不对的,除非在一些奇怪和有限的情况下。
禁用:
window.alert = function() { };
覆盖:
window.alert = function(text) { /* do something */ };
Yes you can, it's your choice. You could also store the original 'alert':
window.nativeAlert = window.alert;
window.alert = function(val){console.log(val+' (alert disabled)');};
now the old alert is still usable: nativeAlert('something');