Javascript is a scripting language that will be executed wherever the browser downloads. This feature will provide convenience for programming, but it can easily make the program too messy and fragmented.
JS can be divided into two parts in terms of function - the framework part and the application part. The framework part provides the organizational role of js code, including defining global variables, namespace methods, etc. Each page will have the same or similar framework. The application part provides page function logic. Different pages will have different functions, and the codes for different pages will be different.
Give the application part of the js code a unified entry, that is:
The code copy is as follows:
<script type="text/javascript">
function init(){
//==================================================
// Comments
// Function, engineer name, engineer contact information, time
//=================================================
(function(){
...aaaaaaaaaa
})();
(function(){
...bbbbbbbbbb
})();
}
</script>
Just call the init() function at the bottom of the page
The code copy is as follows:
//========== Init() call belongs to the framework part code========================================================================================================
<script type="text/javascript">
init();
</script>
//========== Init() call belongs to the framework part code========================================================================================================
Note: The framework code is mainly divided into:
1. Namespace function definition
2. function init(){ } writes the js of the application part
3. Calling of init() function [In case there is no init() written in the main body, but the call can be used in the following writing method]
The code copy is as follows:
<script type="...">
if(init){
init();
}
</script>