This problem is a way I use at work because I need to pack
So think of
CanCan you reference to the function in another JS in one JS?
can greatly reduce the number of code if this can be greatly reduced
First introduce two js files on the HTML page
1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> </title>
</head>
<script src="1.js"></script>
<script src="2.js"></script>
<body>
</body>
</html>
1.js
function a(){
alert(1);
}
2.js
a();
This way 2.JS can directly call the A function in 1.JS
Of course, this is just a very simple way. Write a method of closing (of course it is also very simple ~~)
1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> </title>
</head>
<script src="1.js"></script>
<script src="2.js"></script>
<body>
</body>
</html>
1.js
var dianji;
(function(){
dianji = {
a:function(){
alert(1);
}
}
})()
Here 1.JS is an object function and a closure form, so we need to raise the Dianji variable to the global. In this way, this A function can be called in 2.JS, otherwise the error of the reward variable is not defined.
If you want to call the function between JS, the function must be global
2.js
dianji.a();