The problem was raised because of a recent project in which the design department designed the alert () interface to require development using this design. I had no idea that alert () could be customized, isn't it native? The native can change? But with the depth of study, I found that it is possible, below is my idea:
First we know that all global variables are properties of the Window object, all global functions are the methods of the Window object, and the execution of alert () can do this: Window.alert (); For the Window object, alert is the alert () The reference to the function, we re-set a reference to the alert to a custom function.
The code is as follows:
<script>Window.alert=function () { console.log ("custom Alert");} alert (); </script>
After execution the console really output "custom alert", so we can control the alert () method, do not achieve the desired result? Follow up and start coding yourself.
Customizes the original function of the window.