gpt4 book ai didi

JavaScript YUI3 使用全局变量?

转载 作者:行者123 更新时间:2023-11-29 10:23:53 25 4
gpt4 key购买 nike

我不知道如何从 YUI3 中更新全局变量。

考虑以下代码:

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'

谁能给我解释一下?这给我带来了很多麻烦。为什么可以访问 window.myVariable 但不能从 YUI3 block 中正确更新?

我认为这可能与 Closures 有关但我不明白为什么闭包应该应用于全局“窗口”对象。

帮忙吗?

最佳答案

回调不会立即触发,而是在发生某些事情后触发:

Attaches one or more modules to the YUI instance. When this is executed, the requirements are analyzed, and one of several things can happen:

  • All requirements are available on the page -- The modules are attached to the instance. If supplied, the use callback is executed synchronously.
  • Modules are missing, the Get utility is not available OR the 'bootstrap' config is false -- A warning is issued about the missing modules and all available modules are attached.
  • Modules are missing, the Loader is not available but the Get utility is and boostrap is not false -- The loader is bootstrapped before doing the following....
  • Modules are missing and the Loader is available -- The loader expands the dependency tree and fetches missing modules. When the loader is finshed the callback supplied to use is executed asynchronously.

关于JavaScript YUI3 使用全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6034275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com