Function - Javascript Scope Chain Understanding

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m reading about Scope Chaining at the moment and wanted to paraphrase my understanding of the concept in order to determine whether or not I am understanding it correctly.

My understanding is this:

    • When a new function is initialized an object for this function is created automatically
    • This object has properties which define the variables to be used within that function
    • This object is added to the chain of objects already created
    • If I had a few nested functions, each of those functions will represent a hierarchical object in the scope chain. The deeper the nested function, the further down the chain its relative object lives. (The object which defines its variables).

So, in practice, if function one contained function two and function two contained function 3, and function 3 tried to access a variable - the interpreter would move up the scope chain (starting with its own local scope) to try to find this variable and would do so right up to the uppermost function, stopping the first time it is found?

It d be great if you could give me insight as to whether or not i m totally barking up the wrong tree here or whether or not i m generally on the right track?

Thanks, Jordan

Answers

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/18421196/javascript-scope-chain-understanding

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils