Assuming I deleted window.alert, how would I get it back?

前端 未结 3 1603
遇见更好的自我
遇见更好的自我 2021-01-27 01:51

Assume I do this in javascript

delete window.alert;
// returns true

then the output of console.log(window.alert); will be \"

3条回答
  •  无人及你
    2021-01-27 02:37

    The window object is a normal JavaScript object. You can simply "save" the alert function by keeping a reference to it.

    const alert = window.alert;
    delete window.alert; // window.alert is now undefined
    window.alert = alert;
    

提交回复
热议问题