內建函式 解析

來源:互聯網
上載者:User

標籤:javascript   內建函式   執行   閉包   

<span style="font-size:18px;">function outerFn(){document.write("outer");var i=0;function innerFn(){document.write("inner");i++;document.write(i);}return innerFn;} //要想使用inner()這個內建函式,不可以在outerFn()外部,直接引用</span><span style="font-size:18px;">outerFn()</span><span style="font-size:18px;">//</span><span style="font-size:18px;">outerFn()</span><span style="font-size:18px;">;是錯誤的</span><span style="font-size:18px;">var innerObj=outerFn(); //將outerFn()返回的函數變數賦給innerObj</span><pre name="code" class="javascript"><span style="font-size:18px;">innerObj();//調用一次內建函式</span><span style="font-size:18px;">outerFn</span><span style="font-size:18px;">()</span><pre name="code" class="javascript"><span style="font-size:18px;">innerObj();</span><span style="font-size:18px;">//第二次調用內建函式</span><span style="font-size:18px;">outerFn</span><span style="font-size:18px;">()</span><span style="font-size:18px;"></span>



最近在研究閉包和範圍鏈。很多概念還看不到,現在還不是總結的時候。

上面的那個函數式經常被閉包及相關知識解釋的例子,之前看不到,後來明白了,趕緊來總結此部分。

innerFn()是outerFn()的內建函式,要執行此內建函式,直接在outerFn()外應用innerFn()是不行的。

以上的例子是通過父函數的返回值來獲得內建函式的引用,進而執行內建函式。



內建函式 解析

聯繫我們

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