转:深入理解Javascript闭包

摘要: 最近在网上查阅了不少Javascript闭包(closure)相关的资料,写的大多是非常的学术和专业。对于初学者来说别说理解闭包了,就连文字叙述都很难看懂。撰写此文的目的就是用最通俗的文字揭开Javascript闭包的真实面目。 一、什么是闭包? “官方”的解释是:所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分。 相信很少有人能直接看懂这句话,因为他描述的太学术。我想用如何在Javascript中创建一个闭包来告诉你什么是闭包,因为跳过闭包的创建过程直接理解闭包的定义是非常困难的。看下面这段代码: function a() 阅读全文
posted @ 2011-07-18 15:13 DPlayer 阅读(255) 评论(0) 推荐(2)

How JavaScript Timers Work(from John Resig, http://ejohn.org/blog/how-javascript-timers-work/)

摘要: At a fundamental level it's important to understand how JavaScript timers work. Often times they behave unintuitively because of the single thread which they are in. Let's start by examining the three functions to which we have access that can construct and manipulate timers.var id = setTime 阅读全文
posted @ 2011-07-06 11:44 DPlayer 阅读(199) 评论(0) 推荐(0)

2011年7月1号

摘要: 一个崭新的7月,我在此入住... 阅读全文
posted @ 2011-07-01 09:11 DPlayer 阅读(85) 评论(0) 推荐(0)