我已经像这样定义我的 Controller 一段时间了(没有任何库),但依赖关系让我发疯,现在我正在尝试集成 requireJs。
controller = new function () {
this.test = "Hello World";
this.__construct = function () {
alert(this.test);
};
this.__construct();
};
如何将其转换为 requireJs 模块?我尝试过以下方法
define(function () {
return controller = new function () {
this.test = "Hello World";
this.__construct = function () {
alert(this.test);
};
this.__construct();
};
});
我可以简单地做吗?
define(controller);
在我的主目录
//main.js
requirejs(['controller']);
但是,警报弹出窗口不会显示。
最佳答案
您的 controller
定义应该没问题 - 但是,您在 main.js
中滥用了 require:
//main.js
requirejs(['controller'], function(controller){
// use controller here
});
关于javascript - 在定义模块 requirejs 中使用 new,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36409324/