201506231015_《Javascript權威指南(第六版)——作為命名空間的函數、閉包、 》(P181-193)

來源:互聯網
上載者:User

標籤:

1. 作為命名空間的函數。 形如: var someFn = (function(){var a = 0;return function f(){// ...};}());

2. 閉包。

  閉包內無法直接存取外部函數的參數,除非將外部的實參列給一個變數儲存以來。例如:var outerArguments = arguments;

3. 函數的屬性,方法,建構函式

  a. 
      arguments.length;  (期望傳入的實參個數)

      arguments.callee.lenth;(實際傳入的實參個數)

  b. prototype屬性

    建構函式會從原型對象上繼承屬性和方法;

  c. call()和apply()

     第一個參數是要“要調用函數的母對象”

     形如:函數.call(對象);  函數.apply(對象);

4. bind();——將函數綁定至整個對象;(返回一個函數對象)

  例如:

  function square(x) {return x*x}; var obj = {x : 2}; var newObj = square.bind(obj,obj.x); console.log(newObj());   //4  注意括弧,因      為“square.bind(obj,obj.x);” 是個function類型!!

 

5. toString();

6. Function();建構函式

   a. 傳入任意數量的字串實參;

   b. var fn = new Function("x","y","return x + y;"); fn(2,3);  //5

   c. var scope = "global"; function constructFunction(){var scope = "local";return new Function("return scope")  //無法擷取local};

 

7. 

 

 

 

201506231015_《Javascript權威指南(第六版)——作為命名空間的函數、閉包、 》(P181-193)

聯繫我們

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