/* 匿名函数*/
(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();
// anonymous function.