Home
Web Front-end
JS Tutorial
Introduction to javascript anonymous function application examples_javascript skills



Introduction to javascript anonymous function application examples_javascript skills
May 16, 2016 pm 04:56 PM
javascript
anonymous function
JavaScript anonymous function means that the function has no name. The test code is listed below. 🎜>
/*
* Generally common functions are like this */ function debug(data) { console.log(data); }
But some functions are written like thisCopy the code
The code is as follows:
(function(x, y) {
debug(x y); }) The above is the so-called anonymous function
Copy code
The code is as follows:
var fun = null;
(function() { var test = function(x ,y ) { debug(x y); } fun =test; })();
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:
Copy code
The code is as follows:
var U = {
uid: 32812, gameList: (function(){ var list = new Array(); list[7]= '360'; list[6]='baidu'; if(list != 'null'){ return list;
} }
)(),
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.
)(),
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.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Usage and characteristics of C++ anonymous functions

Simple JavaScript Tutorial: How to Get HTTP Status Code

Python Lambda expressions: abbreviated, concise, powerful

How to get HTTP status code in JavaScript the easy way

Can Golang anonymous functions return multiple values?

How are anonymous functions implemented in golang functions?

Python Lambda Expressions: Making Programming Easier

Python Lambda expressions: Uncovering the power of anonymous functions
