现在的位置: 首页 > 综合 > 正文

ECMA-262-3 in detail. Chapter 4. Scope chain.

2012年05月16日 ⁄ 综合 ⁄ 共 825字 ⁄ 字号 评论关闭

转载地址:http://dmitrysoshnikov.com/ecmascript/chapter-4-scope-chain/

Introduction

As we already know from the second chapter concerning the variable object, the data of anexecution context (variables, function declarations, and formal parameters of functions) are stored as properties of the variables object.

Also, we know that the variable object is created and filled with initial values every time on entering the context, and that its updating occurs at code execution phase.

This chapter is devoted one more detail directly related with execution contexts; this time, we will mention a topic of a scope chain.

Definition

If to describe briefly and showing the main point, a scope chain is mostly related with inner functions.

As we know, ECMAScript allows creation of inner functions and we can even return these functions from parent functions.

var x = 10;
 
function foo() {
 
  var y = 20;
 
  function bar() {
    alert(x + y);
  }
 
  return bar;
 
}
 
foo()();

抱歉!评论已关闭.