Home > Web Front-end > JS Tutorial > body text

JS anonymous function example analysis

高洛峰
Release: 2016-12-05 10:48:16
Original
855 people have browsed it

The examples in this article describe JS anonymous functions. Share it with everyone for your reference, the details are as follows:

/* 匿名函数*/
(function() {
var foo = 10;
var bar = 2;
alert(foo * bar);
})();
/* 匿名函数,带参数 */
(function(foo, bar) {
alert(foo * bar);
})(10, 2);
/* 匿名函数返回值 */
var baz = (function(foo, bar) {
return foo * bar;
})(10, 2);
// baz will equal 20.
/* 匿名函数关闭 */
var baz;
(function() {
var foo = 10;
var bar = 2;
baz = function() {
return foo * bar;
};
})();
baz();
Copy after login


Related labels:
js
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!