JavaScript anonymous function means that the function has no name. The test code is listed below. 🎜>
/*
But some functions are written like this
Copy the code
The code is as follows:
(function(x, y) {
Copy code
The code is as follows:
var fun = null;
At this time, you enter in the browser console fun, you will find that it prints function(x, y){ debug(x y);}. It is obvious that this is a function. If you enter fun(1, 2);, 3 will be printed at this time. Let’s look at the types below.
Copy code
The code is as follows:
var U = {
}
}
)(),
serverList: (function(){
var list = new Array();
list[1188]='360';
list[1165]='baidu';
if(list != 'null'){
return list;
}
}
)(),
channelList: (function(){
var list = new Array();
list[9]='手机游戏网';
return list;
}
)(),
searchName : function(t,id){
if( id == false || /^d $/.test(id) == false ){
return 'This is a function';
}else if(eval(t).hasOwnProperty(id)){
return eval(t)[id];
}else{
return 'test ';
}
}
};
At this time, you enter U in the console; you will find that this is an array. U['searchName '] is a function, and U['qudaoList'] returns a result.