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

前端 未结 3 1713
遇见更好的自我
遇见更好的自我 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:29

    How do you 'undelete' window.alert?

    You would have needed to save a reference of the function:

    var windowAlertBackup = window.alert;
    

    And then:

    window.alert = windowAlertBackup;
    

    What is actually happening?

    Any native window function is actually implemented by the javascript interpreter. In javascript window.alert is a pointer to that native function. window.alert is the only default reference to the native window.alert code.

提交回复
热议问题