JavaScript problem, about refactoring Window.alert (), and then invoking window's original Window.alert () methodBig God, ask a question, if the script tag in the first line to write, refactoring the method of Window.alert (), if you do not move the above refactoring on the basis of the code can only use a statement directly call the original Window.alert () method, there is a way? Window.alert = Window.constructor.prototype.alert cross-examine
Problem solved, thank you very much.
That's what I understand.
1234567 |
window._alert = window.alert //临时保存一下; window.alert = function (){ //写你重构的方法; return ; } //下面你想恢复的话就很简单了 window.alert = window._alert; |
This answer was adopted by netizens
123456789101112 |
<
html
>
<
head
>
<
title
>aa</
title
>
<
script
type
=
"text/javascript"
>
var userName;
function greetUser() {
alert(‘Hello, I am your pet rock.‘);
}
</
script
>
</
head
>
<
body
onload
=
"greetUser();"
></
body
>
</
html
>
|
JavaScript refactoring alert ()