Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

javascript - 函数的[[Scope]]属性(Functions's [[Scope]] property)

I have created a very simple example that will serve as an explanation to my question.

(我创建了一个非常简单的示例,它将作为对我的问题的解释。)

The code is pseudo-code, here it is:

(该代码是伪代码,在这里是:)

var scopePosition = "global";

function outer() {
    var scopePosition = "outer";
}

// debugger; We reached this line to inspect Execution Contexts and Function Objects
outer();

// Execution Contexts
var GlobalExecutionContext = {
    variableObject: {
        scopePosition: "global",
        outer: "pointer to function object called `outer`"
    },
    scopeChain: [GlobalExecutionContext.variableObject],
    this: {}
};

//Function Objects
var outerFunctionObject = {
    [[Scope]]: "pointer to GlobalExecutionContext or GlobalExecutionContext.variableObject or 
    GlobalExecutionContext.scopeChain ???"
};

The question itself is when the function gets created where does its [[Scope]] property points to exactly?

(问题本身是何时创建函数的[[Scope]]属性确切指向何处?)

Is it the Execution Context it was created or Execution Context Variable Object or Executions Context Scope Chain?

(是它创建的执行上下文还是执行上下文变量对象或执行上下文作用域链?)

My best guess would be GlobalExecutionContext.scopeChain, cause that way scope links won't be lost if we had a more nested function inside outer and the process is repeated.

(我最好的猜测是GlobalExecutionContext.scopeChain,这导致如果我们在外部内部有更多嵌套函数并且重复该过程,则不会丢失作用域链接。)

  ask by Tosheen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...