我试图通过Requirejs模块化我的Backbone应用程序,但我似乎无法得到Requirejs来包含Backbone。这是我main.js是被从索引页包括:无法得到requirejs来包含Backbonejs
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");
},
});
});
以下信息会在打印出我的谷歌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
$ works的定义,但_和Backbone的定义不起作用。他们没有定义。任何想法为什么发生这种情况?