http://helma.org/bugs/show_bug.cgi?id=626------- Comment #2 from
breton.slivka@... 2008-09-02 02:51 -------
I agree in principle that it's by design, but not quite in the details. The
unexpected behavior in this bug is due to something javscript has called
"hoisting". What happens is that function definitions get automatically and
transparently moved to the top of the scope (whether that's global scope, or a
function scope), and variable declarations (but not their assignments) get
moved to the top of the scope, just underneath the function definitions.
So if I understand this correctly, this bit of code in the bug
var foo = function() {
return "This is: var foo = function()"; }
function foo() {
return "This is: function foo()";
}
Root.prototype.main_action = function() {
res.write(foo());
}
Gets translated before it's executed into:
function [anonymous1] (){
return "this is: var foo = function()"; }
function foo() {
return "this is: function foo()";
}
function [anonymous2]() {
res.write(foo());
}
var foo;
foo = [anonymous1];
Root.prototype.main_action = [anonymous2]
So as you can see since after hoisting, the variable assignment gets moved
after the function declaration, it takes precedence.
--
Configure bugmail:
http://helma.org/bugs/userprefs.cgi?tab=email------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
_______________________________________________
Helma-dev mailing list
Helma-dev@...
http://helma.org/mailman/listinfo/helma-dev