Jump to content
php.lv forumi

JavaScript spēlīte: Color Lines


Recommended Posts

Globāli mainīgie piemēram ir visi kas tiek izmantoti iekš https://github.com/arnisritins/Color-Lines/blob/master/lines.js#L346 timeout'a. Mainīgais "blocked" nav redzams no šīs rindas un no šīs (jo nav definēts ne funkcijā, ne iekš closure kas to ietver) tāpēc vērtības nonāk window.blocked mainīgajā.

 

Un 50+ rindu funkcijām piemēri ir: https://github.com/arnisritins/Color-Lines/blob/master/lines.js#L180 un https://github.com/arnisritins/Color-Lines/blob/master/lines.js#L552

Edited by mefisto
Link to comment
Share on other sites

Man šķiet, ka tev nav:

 

http://jsfiddle.net/cZU52/

function log(s){
    $('#log').append('<div>'+s+'</div>');
}

(function(){
  var foo = 1,
      
      
      outer = function () {
        log(foo);
        foo = 2;
        bar = 7;
        
        window.setTimeout(function () {
          log(foo);            
          log(window.foo);
          log(bar);
          log(window.bar);
        }, 1000);
      };
  
  outer();
}());

output:

1
2
undefined
7
7

Kā redzams, foo nav globālais.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...