-
 
- Each variable on create get [[Scope]] - link on object in context where it was created  
- [[Scope]] - is private internal property of function  
- On function call: create a new object with LexicalEnvironment's (LE) variables. This object get link on external object from [[Scope]]  
- Searching variables: at first it search in current variable's object and then by link [[Scope]]
Example
function saySomething(text) {
// LexicalEnvironment = {sign: undefined}
var sign = '!!!';
// LexicalEnvironment = {sign: '!!!'}
console.log('I say ' + text);
function getText(text) { // [[Scope]] -> {sign: '!!!'}
return text;
}
}
saySomething('Hello World');
Where:
saySomething.[[Scope]] = window
getText.[[Scope]] = variable's object of current saySomething() call.
Комментариев нет:
Отправить комментарий