The code copy is as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
* The meaning of anonymous function self-tuning:
1. Create a closed space
2. Prevent variable conflicts
3. Selective external development (third-party frameworks are encapsulated in this way)
*/
//=============================================================================================================================================================================================================================================================
//The action to be executed by the callback
function callback(){
alert("Help me get the express delivery");
}
//Things are about to be done
function goShopping(a,fun){
alert("I went shopping");
//What do you want to do before 10 o'clock
if(a<10){
fun();
}
}
//Callback test
goShopping(9, callback);
//This small example is a scenario for using a callback function: when certain functions are executed, you don’t know what you might do in the future.
//At the same time, if certain conditions are met, other actions will be done, and this action will destroy the function.
//=============================================================================================================================================================================================================================================================
//======================= Callback for anonymous function==============================================================================================================================================================================================================================
//Things are about to be done
function goShopping(a,fun){
alert("I went shopping");
//What do you want to do before 10 o'clock
if(a<10){
fun();
}
}
goShopping(9,function(){
alert("Help me get the express delivery");
});
//======================= Callback for anonymous function==============================================================================================================================================================================================================================
//========================= Calling anonymous function by yourself===========================================================================================================================================================================================================================
function(){
alert("I have no name, how to run");
}();
//==================== Calling the anonymous function with parameters by yourself=============================================================================================================================================================================================================================
function(name){
alert("I am"+name);
function test(){"I am a spy of Danei!"};
//To externally call the internal test
window.test=test;
}("javaScript");
//Calling the internal function of the self-keying function
test();
//Then the js frameworks such as jquery are written in the above way.
//========================= Calling anonymous function by yourself===========================================================================================================================================================================================================================
</script>
</head>
<body>
</body>
</html>