我在http://kilon.org/blog/2012/08/build-backbone-apps-using-requirejs/关注 Uzi Kilon 的 BackboneJS/RequireJS/backbone.LocalStorage 示例。
当我git clone https://github.com/uzikilon/Todos
它工作得很好 - 但它使用旧版本的backbone.localstorage。但是,如果我lib/backbone.localStorage
用较新的版本替换http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.1.0/backbone.localStorage-min
,那么我会在这里得到“Uncaught TypeError: undefined is not a function”:https ://github.com/uzikilon/Todos/blob/master/js/models/Todo.js#L3 - 为什么?我认为这与http://requirejs.org/docs/api.html#config-shim的棘手细节有关,或者可能是这个:http ://blog.mostlystatic.com/2013/01/backbone-localstorage -uncaught.html。
require.config({
baseUrl: "./js/",
paths: {
jquery: 'lib/jquery-1.8.2',
underscore: 'lib/underscore-1.4.2',
backbone: 'lib/backbone-0.9.2',
// 'backbone.localStorage': 'lib/backbone.localStorage'
'backbone.localStorage': 'http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.1.0/backbone.localStorage-min'
},
shim: {
underscore: {
exports: "_"
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'backbone.localStorage': {
deps: ['backbone'],
exports: 'Backbone'
}
}
});