函数直接量
函數(shù)直接量其實就是匿名函數(shù)數(shù),函數(shù)的字面量function???
<script?language="javascript"?type="text/javascript">
????????//函數(shù)直接量(作為表達(dá)式)創(chuàng)建匿名函數(shù) ????????var?test1=function(x) ??????? { ????????????return?x*x; ??????? } ????????document.write(test1(2),"<br />"); ????????//指定函數(shù)名,遞歸調(diào)用 ????????var?test2=function?fact(x)//fact并不是函數(shù)名,而是為了遞歸調(diào)用方便的一個代號 ??????? { ????????????if(x<=1) ??????????? { ????????????????return?1; ??????????? } ????????????else?{ ????????????????return?x?*?fact(x?- 1);?//5*4*3*2 ??????????? } ??????? } ????????document.write(test2(5),"<br />");??? ????????//等同于上述遞歸 ????????var?result=1; ????????for(var?i=1;i<=5;i++) ??????? { ????????????result=result*i; ??????? }?? ????????document.write(result); ????</script>轉(zhuǎn)載于:https://www.cnblogs.com/chengpeng/archive/2011/08/09/2132251.html
總結(jié)
- 上一篇: 做网管这么久了,每个月只是拿1000元的
- 下一篇: 英语语音再学习