JavaScript YUI3 using global variables?

I cannot decide how to update a global variable from YUI3.

Consider the following code:

window.myVariable = 'data-one';
var yuiWrap = YUI().use('node',function(Y) {
  console.log(window.myVariable); // 'data-one'
  window.myVariable = 'data-two';
  console.log(window.myVariable); // 'data-two'
});
console.log(window.myVariable); // 'data-one'

Can someone explain this to me? It causes me a lot of trouble. Why can the .myVariable window be accessed but not properly updated from the YUI3 block?

I think this may have something to do with Closures , but I don’t understand why Closures should be applied to the global “window” object.

reference

+3
source share
1 answer

The callback does not start immediately, but after something happened:

YUI. , , :

  • - . .
  • , Get "bootstrap" . .
  • , , Get boostrap - , ....
  • Loader - . , , , .
+4

All Articles