javascript中巧用“闭包”实现程序的暂停执行功能
发布时间:2016-12-30 来源:查字典编辑
摘要:Author:月影Form:http://bbs.51js.com/thread-66361-1-1.html/*基本原理*/varst=(...
Author:月影
Form:http://bbs.51js.com/thread-66361-1-1.html
<inputtype="button"value="继续"onclick='st();'/>
<script>
/*基本原理*/
varst=(function(){
alert(1);
alert(2);
returnfunction()
{
alert(3);
alert(4);
}
})();
</script>
<inputtype="button"value="继续"onclick='st();'/>
<script>
/*函数*/
functiontest(x)
{
alert(x++);
alert(x++);
returnfunction()
{
alert(x++);
alert(x++);
}
}
varst=test(10);
</script>
<inputtype="button"value="继续"onclick='st();'/>
<script>
/*函数嵌套*/
functiona(x,y)
{
varst2=b(x+y);
returnfunction()
{
st2=st2();
alert(st2);
}
}
functionb(a)
{
alert(a++);
alert(a++);
returnfunction()
{
alert(a++);
alert(a++);
returna;
}
}
varst=a(10,20);
</script>