Javascript學習-執行內容(Execution Contexts)

來源:互聯網
上載者:User

標籤:

一。ECStack

執行內容是一個堆棧,每次進入function時,則會將該function context壓入棧,當從function 退出時候,則會從ECStack彈出該Function context.

二。Global Contexts

在程式初始化時候,則會壓入到ECStacks中,例如:

 

ECStack = [  globalContext];
三。Function Code

當執行進入Function時,ECStack 將會push 進一個新的Item,需要注意的是,該新的Item不包含Function內部的Funtion.

 

(function foo(flag) {  if (flag) {    return;  }  foo(true);})(false);
當遞迴執行foo時候,ECStack的狀況表現如下:
// first activation of fooECStack = [  <foo> functionContext  globalContext];  // recursive activation of fooECStack = [  <foo> functionContext – recursively   <foo> functionContext  globalContext];

 

對於拋出未被catch的異常,將會導致從一個或者多個Context中退出。

四。Eval Code

eval 定義的變數和函數,影響的是調用該 eval的context,例如:

// influence global contexteval(‘var x = 10‘); (function foo() {  // and here, variable "y" is  // created in the local context  // of "foo" function  eval(‘var y = 20‘);})();  alert(x); // 10alert(y); // "y" is not defined
ECStack = [  globalContext];  // eval(‘var x = 10‘);ECStack.push({  context: evalContext,  callingContext: globalContext}); // eval exited contextECStack.pop(); // foo funciton callECStack.push(<foo> functionContext); // eval(‘var y = 20‘);ECStack.push({  context: evalContext,  callingContext: <foo> functionContext}); // return from eval ECStack.pop(); // return from fooECStack.pop();

Javascript學習-執行內容(Execution Contexts)

聯繫我們

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