Disable a built-in function in javascript (alert)

后端 未结 2 1388
失恋的感觉
失恋的感觉 2020-12-18 11:25

Simple: I want to disable/overwrite alert().

Can I do this?

More importantly, is it right to do this?

What about strict mode?

2条回答
  •  不思量自难忘°
    2020-12-18 12:07

    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');

提交回复
热议问题