• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
天道酬勤
echo "See you,World!";
博客园    首页    新随笔    联系   管理    订阅  订阅

最近总结的一段代码

该段代码集结了匿名函数(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

文章仅作一个人笔记,取消注释可以知道更多。。。

posted @ 2011-09-23 16:28  enimo  阅读(157)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3