How to write a method in the previous JS file and call it in the following page method (a bit of a mouthful, click for details)

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326448920&siteId=291194637