我試圖通過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的定義不起作用。他們沒有定義。任何想法爲什麼發生這種情況?