requireJS:定义用作全局变量的类
由于某种原因,我真的似乎无法理解 RequireJS (查看了各种其他问题)
一些背景:
- 我正在使用 jquery (所以没有 Node.js 自动构建的东西)
- 我正在使用客户端 mVC lib 库(在我的例子中,它作为其设置的一部分,在其代码深处执行
require("Avail")
。 - 'Avail' 是一个 javascript 类,它作为 window.Avail 全局存在,
我收到错误消息
未捕获错误:模块名称 'Avail' 尚未加载到上下文:_ http://requirejs.org/docs/errors.html#notloaded
我知道它没有加载,但如何做到这一点?当我的应用程序启动时,有没有办法告诉 requireJS 在默认上下文“_”下注册“Avail”?
我已经尝试了如下几种方法(以及很多变体,但我无法让它工作):
(function() {
define("Avail", [],function(){
return window.Avail
});
})();
非常感谢帮助。谢谢。
I really can't seem to grok RequireJS for some reason (having looked at various other questions)
Some background:
- I'm using jquery (so no Node.js automatic build stuff)
- I'm using a client-side mVC lib library (spine.js) which as part of it's setup, in my case, does
require("Avail")
deep inside it's code. - 'Avail' is a javascript-class which is present globally as window.Avail
I'm getting the error-msg
Uncaught Error: Module name 'Avail' has not been loaded yet for context: _
http://requirejs.org/docs/errors.html#notloaded
I get that it isn't loaded but how to do that? Is there a way to tell requireJS to register 'Avail' under the default context "_" when my app starts up?
I've tried several things like below (and lots of variations on that but I can't get it to work):
(function() {
define("Avail", [],function(){
return window.Avail
});
})();
Help much appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,尽管 Spine.js 的代码中已经对“models/Avail”进行了要求,但我自己也必须对“models/Avail”进行要求。
文件:spine.models.coffee
文件:main.html
It turned out that even though Spine.js in it's code already did a require on 'models/Avail', I had to do a require myself on 'models/Avail' as well.
file: spine.models.coffee
file: main.html