我正在尝试通过 Requirejs 模块化我的 Backbone 应用程序,但我似乎无法让 Requirejs 包含 Backbone。这是我的 main.js,它包含在索引页面中:
require.config({
baseUrl: '/static/js/',
paths: {
jquery: 'libs/jquery/jquery-min',
underscore: 'libs/underscore/underscore-min',
backbone: 'libs/backbone/backbone-min',
text: 'libs/require/text',
},
});
require(['/static/js/views/app.js'], function(AppView) {
var appView = new AppView;
});
这是从上述文件中包含的我的 app.js:
define([
'jquery',
'underscore',
'backbone',
], function($, _, Backbone) {
console.log($);
console.log(_);
console.log("inside of the app js file");
var AppView = Backbone.View.extend({
initialize: function() {
console.log("inside of appview initialize");
},
});
});
以下信息会在我的 Google Chrome 控制台中打印出来:
function (a,b){return new e.fn.init(a,b,h)}
app.js:7undefined
app.js:8inside of the app js file
app.js:9Uncaught TypeError: Cannot read property 'View' of undefined
$ 的定义有效,但 _ 和 Backbone 的定义无效。它们以未定义的形式出现。知道为什么会这样吗?