R
RobG
I'm sure this has been discussed before but I can't find it. The
following code:
var foo;
(function() {
foo = function foo(){};
}());
alert(typeof foo);
shows "function" in most browsers but "undefined" in IE. It appears
that IE is creating a local variable foo inside the anonymous function
as a consequence of the named function expression. So the function is
assigned to a local variable and goes out of scope for the alert. But
in non-IE browsers, foo resolves to the global foo and is in scope for
the alert.
Is this consistent with ECMA-262 or not? I'm simply not up to wading
through the spec in sufficient detail to answer the question myself.
following code:
var foo;
(function() {
foo = function foo(){};
}());
alert(typeof foo);
shows "function" in most browsers but "undefined" in IE. It appears
that IE is creating a local variable foo inside the anonymous function
as a consequence of the named function expression. So the function is
assigned to a local variable and goes out of scope for the alert. But
in non-IE browsers, foo resolves to the global foo and is in scope for
the alert.
Is this consistent with ECMA-262 or not? I'm simply not up to wading
through the spec in sufficient detail to answer the question myself.