For example, there is an html page, which is roughly as follows:
<script type="text/javascript" src="xx.js"></script>
function a(){
alert(1);
}
Where xx.js is as follows:
function a(){
alert(2);
alert(1);
}
We know that the a method in xx.js will be overwritten by the following a method, so that alert(2) will not be executed first, so what should we do?
Modify as follows:
function b(){
}
<script type="text/javascript" src="xx.js"></script>
function a(){
b();
alert(1);
}
Where xx.js is as follows:
function b(){
alert(2);
}
After this modification, alert(2) will be executed first, and if xx.js does not exist, the code will not go wrong.