F
florian.loitsch
I wondered what should be the result of the following code:
===
function f() {
x = false;
function x() {};
alert(x);
}
===
According to Ecmascript-spec we have the following rules:
10.1.3: "For each FunctionDeclaration ... create a property of the
variable object whose name is the Identifier... whose value is ... a
Function object"
but also
13: For FunctionDeclaration: "1. Create a new Function object... 2.
Create a property of the current variable object (...) with name
Identifier and value Result(1)."
It seems that according to these rules, there should be two creations
of function objects for each Function Declaration. One when the
function starts, and one, when we reach the line of the function-
declaration. And following this reasoning the program should alert
"function x() {}", and not 'false'.
Any comments?
// florian loitsch
===
function f() {
x = false;
function x() {};
alert(x);
}
===
According to Ecmascript-spec we have the following rules:
10.1.3: "For each FunctionDeclaration ... create a property of the
variable object whose name is the Identifier... whose value is ... a
Function object"
but also
13: For FunctionDeclaration: "1. Create a new Function object... 2.
Create a property of the current variable object (...) with name
Identifier and value Result(1)."
It seems that according to these rules, there should be two creations
of function objects for each Function Declaration. One when the
function starts, and one, when we reach the line of the function-
declaration. And following this reasoning the program should alert
"function x() {}", and not 'false'.
Any comments?
// florian loitsch