日期:2014-05-16  浏览次数:20278 次

javascript的匿名函数写法和应用
javascript 的匿名函数常见形式or格式:
(function(参数名){
	//do something
})(参数值);

//eg:
(function(a){
	alert("显示:"+a);//显示:我的
})('我的');
//相当于给参数a传一个值:'我的'
//eg2: 不带参数的匿名函数
(function () {
    alert("---running...");
})();


这个写法等价于:
//声明一个函数: xxxx
function  xxxx(参数名){
	//do something
}
//调用该函数
xxxx(参数值);

还有更诡异的写法:
(function(b){
    alert(b);//显示: hello
    return function(c){
        alert(c);//显示: world
    };
})('hello')('world');

(function(a){
   alert(a);//不断的弹出显示 a接着显示b接着显示c....
   return arguments.callee;
})('a')('b')('c')('d')('e')('f');//事实上后面可以无限连续调用下去