在我的 main.js 文件中:
define(['require'], function(require) {
require([
'../libs/requirejs/plugins/domReady',
'../core',
'../ndn.2',
'../Ndn/Widget'
],
function(domReady) {
// require('../Ndn/Widget'); // I tried this too, but it doesn't solve my problem
console.log('Should have required everything...');
domReady(function() {
console.log('About to call init()');
init();
});
}
)});
function init() {
// Begin fetching this widget's delivery settings
Ndn_Widget.fetchDeliverySettings();
// ... Other code here ...
}
在我的 Ndn/Widget.js 文件中,我有以下内容:
var Ndn_Widget;
define(['require'], function(require) {
require(['../ndn.2', './ServerInterface'], function() {
/**
* An associative array for the different delivery settings
* @var Object
*/
var deliverySettings = {};
Ndn_Widget = {
fetchDeliverySettings: function() {
// ... code here
console.log('Finished defining Ndn_Widget.');
}
};
});
});
我希望我传递给 main.js 中的 define() 函数的匿名函数只会在“../Ndn/Widget.js”文件加载后执行,但情况并非总是如此。
这是我的 console.log 语句的示例:
Should have required everything...
About to call init()
Uncaught TypeError: Cannot call method 'fetchDeliverySettings' of undefined
Just finished defining Ndn_Widget.
有人可以告诉我我做错了什么吗?先感谢您!