Monday 15 March 2010

javascript - Scope within HTML5 member function -


I am an ancient programmer trying to use HTML5 with some difficulty, I used to call a global function "MouseSandler" With the local variables in that function including X and Listsong.

is within a function Muvhandlr Maushandlr, and if (PostFunc) is a breakpoint on I get the value of local variables:

  1. Abisisarar "Kyukyuclyu" is
  2. Difset "under 417,358"
  3. last message "below 417,358"
  4. Mouse.LastMsg is "QQQ"
  5. X is 417
  6. LocalX is 417

    The code is:

      var MouseHandler = function (canvas1, terraincvs1, PostFunc1) {// ... var X, Y; Var LastMsg = "QQQ"; // ... function HillHandler () {var ABCStr = Mouse.LastMsg; Var DEFStr = LastMsg; Var localx = x; // ... LastMsg = "move" + X + ',' Y; If PostFunc (); Return ( "last" message: LastMsg}} cvs.addEventListener ( "Musudaun" Daunlaistnr, false); "DAS" DX, "DY" DY "Daunaks" Daunaks, down Listnr, "Holhandlr" Muvhandlr, Offset X "Ofsetaks, offset Y" "Daunwai" down Y "down" down, "Lastmogj" Lastmog}} // ... var icons = new Maushandlr (canvas, hexa Kanws, Postmous);   

    It seems that the value of the "X" defined in the outer function Mauschandler for localax Has been set up properly, but Antrmndl Holhandr within LastMsg a (implicitly declared) local variable appears, but the reference mouse than to define the final message in the outer function Maushandlr (as I expected) Experimenting. LSTMsg seems to be the value of the last message of the external function, as can be expected.

    Am I clarifying something here? Can I direct for an online reference to the realm of variables for HTML5 which will explain this issue to me?

    These scoping problems are completely related to JavaScript, and not much HTML5.

    Javascript's variable scope, though the C-family is likely to be similar to block scope, actually the function level scripts will start with the Javascript interiors function and "Hull" will be searched for variables, therefore because your LastMsg the definition of your MoveHandler () was not in function, went JavaScript your MouseHandler anonymous defined in the variable function within the Open the series and met him at LastMsg string QQQ and solved.

    When you change LastMsg into the MoveHandler () function, then Javascript skips the QQQ value only and Creates a new string and specifies the reference to that variable because JavaScript strings are irreversible .

    There are good links to read about this:



No comments:

Post a Comment