I am an ancient C programmer attempting to use HTML5, with some difficulty. I have defined a global function "MouseHandler" with variables local to that function including X and LastMsg.
A function MoveHandler is within MouseHandler, and placing a breakpoint at if (PostFunc)
I find the value of the local variables to be:
- ABCStr is "QQQ"
- DefStr is "Down 417,358"
- LastMsg is "Down 417,358"
- Mouse.LastMsg is "QQQ"
- X is 417
- LocalX is 417
The code is:
var MouseHandler = function (canvas1, terraincvs1, PostFunc1)
{
// ...
var X, Y;
var LastMsg = "QQQ";
// ...
function MoveHandler ()
{
var ABCStr = Mouse.LastMsg;
var DEFStr = LastMsg;
var LocalX = X;
// ...
LastMsg = "Move " + X + ',' + Y;
if (PostFunc)
PostFunc ();
return { "LastMsg" : LastMsg }
}
cvs.addEventListener("mousedown", DownListener, false);
return { "DownListener" : DownListener, "UpListener" : UpListener, "MoveHandler" : MoveHandler,
"OffsetX" : OffsetX, "OffsetY" : OffsetY, "dX" : dX, "dY" : dY, "DownX" : DownX, "DownY" : DownY, "Down" : Down,
"LastMsg" : LastMsg }
}
// ...
var Mouse = new MouseHandler (canvas, HexCanvas, PostMouse);
It seems that LocalX is appropriately set to the value of "X" defined within the outer function MouseHandler, but LastMsg seems to be an (implicitly declared) local variable within the inner MoveHandler, rather than referring (as I expected) to the LastMsg defined within the outer function MouseHandler. Using the reference Mouse.LastMsg appears to refer to the value of the outer function's LastMsg, as might be expected.
Am I missing something obvious here? Can somebody direct me to an online reference for scope of variables for HTML5 that would clarify this issue for me?