A
Asen Bozhilov
Today i read one article in one blog. Article title is:
"Internet Explorer Scope Resolution"
| Scope variables are resolved after functions and
| unless we forget to assign a value,
| leaving them undefined, these variables will have a privileged
reference.
| This means that if we declare var foo = null;
| exactly at the top of above example scope,
| the latter one will consider foo a null reference.
Maybe someone will be say, "your english is bad". Yes my english is
not very well. But the text above is completely wrong. ECMA 3
documentation explains each of point here.
| (function(){
| alert(foo); // the function!
| // function foo(){/* 2 */}
| var foo = null;
| alert(foo); // null
| function foo(){/* 1 */};
|
| function foo(){/* 2 */};
| alert(foo); // null
| })();
Identifiers for function and variable declaration will be added as
property of Variable Object on entering in execution context.
| 10.1.3 Variable Instantiation
| For each FunctionDeclaration in the code,
| in source text order, create a property of the variable object
whose
| name is the Identifier in the FunctionDeclaration,
| whose value is the result returned by creating a Function object
| .....
| If the variable object
| already has a property with this name,
| replace its value and attributes.
| For each VariableDeclaration or VariableDeclarationNoIn in the code
| If there is already a property of the variable object with
| the name of a declared variable,
| the value of the property and its attributes are not changed.
| 10.1.4 Scope Chain and Identifier Resolution
| During execution ...
| alert(foo); // the function!
| // function foo(){/* 2 */}
After quotation from ECMA3 documentation that is absolutely expected
behaviour. And that:
(function(){
window.alert(foo); //reference to `function'
function foo(){};
var foo;
})();
variable declaration with identifier `foo' can't change attributes and
value of property with name `foo' of Activation/Variavble Object.
| var foo = null;
| alert(foo); // null
Again expected behaviour. Assignment expression will be executed
runtime and will be replace value of property `name' with value
produced from assignment expression.
| 11.13 Assignment Operators
| 2. Evaluate AssignmentExpression.
| 3. Call GetValue(Result(2)).
Before i read c.l.js i was read many tutorial about JavaScript. All of
that tutorials doesn't have reference to ECMA262 documentation. When i
start to read here, i don't understand many things about ECMA262. Now
again i don't understand many things, but here is only place where i
get relevant information about ECMA262.
The man who produced that article have title "javascript ninja". What
mean that? After a few months i read one article produced from Garrett
Smith about "javascript magic". At the moment i don't see Garret Smith
article.
Why all of that? Why i don't see one good book for ECMA 262
(JavaScript)?
"Internet Explorer Scope Resolution"
| Scope variables are resolved after functions and
| unless we forget to assign a value,
| leaving them undefined, these variables will have a privileged
reference.
| This means that if we declare var foo = null;
| exactly at the top of above example scope,
| the latter one will consider foo a null reference.
Maybe someone will be say, "your english is bad". Yes my english is
not very well. But the text above is completely wrong. ECMA 3
documentation explains each of point here.
| (function(){
| alert(foo); // the function!
| // function foo(){/* 2 */}
| var foo = null;
| alert(foo); // null
| function foo(){/* 1 */};
|
| function foo(){/* 2 */};
| alert(foo); // null
| })();
Identifiers for function and variable declaration will be added as
property of Variable Object on entering in execution context.
| 10.1.3 Variable Instantiation
| For each FunctionDeclaration in the code,
| in source text order, create a property of the variable object
whose
| name is the Identifier in the FunctionDeclaration,
| whose value is the result returned by creating a Function object
| .....
| If the variable object
| already has a property with this name,
| replace its value and attributes.
| For each VariableDeclaration or VariableDeclarationNoIn in the code
| If there is already a property of the variable object with
| the name of a declared variable,
| the value of the property and its attributes are not changed.
| 10.1.4 Scope Chain and Identifier Resolution
| During execution ...
| alert(foo); // the function!
| // function foo(){/* 2 */}
After quotation from ECMA3 documentation that is absolutely expected
behaviour. And that:
(function(){
window.alert(foo); //reference to `function'
function foo(){};
var foo;
})();
variable declaration with identifier `foo' can't change attributes and
value of property with name `foo' of Activation/Variavble Object.
| var foo = null;
| alert(foo); // null
Again expected behaviour. Assignment expression will be executed
runtime and will be replace value of property `name' with value
produced from assignment expression.
| 11.13 Assignment Operators
| 2. Evaluate AssignmentExpression.
| 3. Call GetValue(Result(2)).
Before i read c.l.js i was read many tutorial about JavaScript. All of
that tutorials doesn't have reference to ECMA262 documentation. When i
start to read here, i don't understand many things about ECMA262. Now
again i don't understand many things, but here is only place where i
get relevant information about ECMA262.
The man who produced that article have title "javascript ninja". What
mean that? After a few months i read one article produced from Garrett
Smith about "javascript magic". At the moment i don't see Garret Smith
article.
Why all of that? Why i don't see one good book for ECMA 262
(JavaScript)?