On 07.09.2011 14:49, Dmitry Pashkevich wrote:
Yeah the question itself is tricky.
But anyway, can somebody please give a clear explanation of why can't
we override the name of the function expression if we call it
immediately but this code:
var x = function (){x=123;alert(x);};
x();
will assign 123 to x?
Because in case of a variable, "x" is name of the _variable_, not a
function's name (more precisely, the name of a binding in the
environment). And this variable is not read-only, you may assign to it
(while cannot to function's name). Besides, it's not required that the
function should have the same name as a name of a binding to which it's
attached:
var foo = function bar() {
alert(foo == bar);
};
foo(); // true
P.S.: Notice, there're some bugs in older versions of IE, where this
equality is false
(http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#nfe-and-jscript).
Dmitry.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/jsmentors@jsmentors.com/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/jsmentors@googlegroups.com/
To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com