Javascript–Function/arguments

來源:互聯網
上載者:User

描述:

建立新的函數.

文法:

    1. function funName([argu1[,argu2[,...[,arguN]]]]){}
    2. var funName = Function([argu1[,argu2[,...[,arguN]]]]){}

funName是必不可少的.

例子:

例子 效果
        function add(x,y){            return x+y;        }                document.write(add(1,2));
3
        var add = new Function("x","y","return x+y");                document.write(add(1,2));
3

 

屬性:

屬性 描述
arguments 對當前執行的function對象返回一個arguments對象
caller 返回一個對函數的引用,該函數調用了當前函數

 

 

arguments:

不能顯示的建立arguments對象,arguments對象只有在函數開始時才可用.

函數的arguments對象並不是一個數組,但可以想數組一樣使用下標去訪問.

屬性 描述
[i] i:必須.
返回第i個參數的值
文法:
arguments[i]
length 返回該函數的參數的個數
文法:
arguments.length
callee 返回正在被執行的Function對象,即返回自身

例子:

例子 效果
        function Calls(x,y){                        document.write("args:"+arguments.length+"<br/>");            for(var i=0;i<arguments.length;i++){                document.write("args["+i+"]="+arguments[i]+"<br/>");            }        }                Calls(1,2);
        function add(x){            if(x==1){                return 1;            }else{                return x+arguments.callee(x-1);            }        }                document.write(add(100));
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.