javascript函數自整理

來源:互聯網
上載者:User

標籤:type   訪問   func   script   函數   並且   cti   ret   參數   

1.定義函數的3種方式:

//1.function語句只會解釋一次,並且後面的會覆蓋前面的,優先解析function test1(){    console.log(‘test1‘);}test1();//2.函數直接量只會解釋一次,並且後面的會覆蓋前面的,順序解析var test2=function(){    console.log(‘test2‘);}test2();//3.每次執行每次動態new一次var test3=new Function("a","b","return a+b;");//頂級範圍,順序解析console.log(test3(1,2));

2.函數的參數:

function fun(a,b,c,d){    console.log(fun.length);//形參個數    //arguments 對象:可以訪問實際參數個數,內部是一個數組,只能在函數內部使用,常用於遞迴操作    console.log(arguments.length);    console.log(typeof arguments);    console.log(arguments);    //arguments.callee指向函數自身(fun)    if( arguments.callee.length == arguments.length ){        return a+b;    }else{        console.log(‘傳參錯誤!‘);    }}fun(1,2,3);

 

javascript函數自整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.