Anonymous functions, as the name implies, have no name. The following is a good example. You can learn about javascript anonymous functions. That is to say, a function has no name. The following lists the test code first.
The Code is as follows:
/*
* This is a common function.
*/
Function debug (data ){
Console. log (data );
}
But some functions are written like this.
The Code is as follows:
(Function (x, y ){
Debug (x + y );
})
The above is the anonymous function.
The Code is as follows:
Var fun = null;
(Function (){
Var test = function (x, y ){
Debug (x + y );
}
Fun = test;
})();
At this time, you enter fun in the browser console, and you will find that it prints function (x, y) {debug (x + y) ;}obviously This is a function, if you enter fun (1, 2), 3 is printed at this time. Next let's take a look at the types.
The Code is as follows:
Var U = {
Uid: 32812,
GameList: (function (){
Var list = new Array ();
List [7] = '123 ';
List [6] = 'baidu ';
If (list! = 'Null '){
Return list;
}
}
)(),
ServerList: (function (){
Var list = new Array ();
List [1188] = '000000 ';
List [1165] = 'baidu ';
If (list! = 'Null '){
Return list;
}
}
)(),
ChannelList: (function (){
Var list = new Array ();
List [9] = 'Manual net ';
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 this is an array. U ['searchname'] is a function, and U ['qudaolist'] returns a result.