左手抓右手

右手加左手

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在函数内部,有两个特殊的对象—arguments和this。arguments主要是保存函数的参数,但是这个对象还有一个叫callee的属性,该属性是一个指针,指向拥有这个arguments对象的函数。

<script type="text/javascript">

    function factorail(num){
        if(num <= 1){
            return 1;
        }else{
            return num * factorail(num - 1);
        }
    }
    document.write(factorail(5)+"<br />");
    function factorail2(num){
        if(num <= 1){
            return 1;
        }else{
            return num * arguments.callee(num - 1);
        }
    }
    document.write(factorail2(5));
</script>

我们已经知道,函数就是对象,因此,函数也有属性和方法。每个函数都包含两个默认的属性,length和prototype。length表示函数希望接收的命名参数的个数。prototype将在后面博文中详细介绍。

<script type="text/javascript">
    function sayName(name){
        alert(name);
    }
    function sum(a,b){
        alert(a+b);
    }
    function sayHi(){
        alert("Hi");
    }
    
    alert(sayName.length);
    alert(sum.length);
    alert(sayHi.length);
</script>
posted on 2012-06-26 16:09  yansj1997  阅读(484)  评论(0编辑  收藏  举报