// Filename: bootstrap
// Require.js allows us to configure shortcut alias
// There usage will become more apparent futher along in the tutorial.
require.config({
paths: {
bfwd: 'com/bfwd',
plugins: 'jquery/plugins',
ui: 'jquery/ui',
jquery: 'jquery/jquery.min',
'jquery-ui': 'jquery/jquery-ui.min',
backbone: 'core/backbone.min',
underscore: 'core/underscore.min'
}
});
console.log('loading bootstrap');
require([
// Load our app module and pass it to our definition function
'app',
'config'
], function(App){
// The "app" dependency is passed in as "App"
// Again, the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
console.log('initializing app');
App.initialize();
});
app.js被正确加载,它的依赖项也被加载。它的定义回调被调用,并传递了所有正确的依赖项作为参数,没有错误抛出。然而,在引导程序的回调中,App未定义!没有传递任何参数。这可能是什么原因?以下是我的应用程序文件(已修改以节省空间)
// Filename: app.js
define(
'app',
[
'jquery',
'underscore',
'backbone',
'jquery-ui',
'bfwd/core',
'plugins/jquery.VistaProgressBar-0.6'
],
function($, _, Backbone){
var initialize = function()
{
//initialize code here
}
return
{
initialize: initialize
};
}
);
define
函数吗?此外,通常最好使用匿名定义。因此,也许可以从模块中删除'app'
代码。 - Paul Grimedefine
?另外,我已经尝试过带有和不带有'app'声明的情况。 - LordZardeck