该段代码集结了匿名函数(arguments.callee)的使用,灵巧的递归方法,以及闭包内函数的重载实现局部变量和局部方法可用。
整段代码是在实现输入为空时进行闪动警报而想到的。
// a elegant function demo include many fantasy features
var timeout = function(time){var time = time || 3,
elem = document.getElementById(“demo”);function funca(){ alert(“funca”)}
function funcb(){ alert(“funcb”)}timeout = function(){ // 1.the funciton to be overwrite here, not overload
//alert(time)
//some handler && render here…
//e.g.
elem.style.background = time&1 ?”#eee” : “#fff”;//some test case below:
//2.can call closure func even though next time
//funca();//3.call func himself
//arguments.callee();time–&&setTimeout(arguments.callee, 200);
}return timeout();
//4.if you need return more api to be called, use the method below:
//return {a:funca,b:funcb}}(4); //5.auto fire after func load
文章仅作一个人笔记,取消注释可以知道更多。。。