我正在尝试了解TodoMVC的Backbone + RequireJS版本。我不明白为什么在main.js文件中,骨干包不依赖?
// Require.js allows us to configure shortcut alias
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'underscore': {
exports: '_'
},
'backbone': {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
}
},
paths: {
jquery: 'lib/jquery/jquery.min',
underscore: '../../../assets/lodash.min',
backbone: 'lib/backbone/backbone',
text: 'lib/require/text'
}
});
require([
'views/app',
'routers/router' // <--views/app.js and routers/router.js are the only dependencies
], function( AppView, Workspace ) {
// Initialize routing and start Backbone.history()
new Workspace();
Backbone.history.start(); // <--Here we use Backbone variable. Where do the writer tell the page about the backbone dependency??
// Initialize the application view
new AppView();
});
答案 0 :(得分:0)
Backbone通过填充程序配置导出为全局,因此不必定义依赖项,因为它已在全局名称空间中可用。