使用RequireJS加载主干和下划线
我正在尝试使用RequireJS加载Backbone和Underscore(以及jQuery)。使用最新版本的Backbone和Underscore,似乎有些棘手。例如,Underscore自动将自身注册为模块,但是Backbone假定Underscore在全球范围内可用。我还要注意,Backbone似乎并没有将自己注册为模块,这使其与其他库有些不一致。这是我能想到的最好的main.js: require( { paths: { 'backbone': 'libs/backbone/backbone-require', 'templates': '../templates' } }, [ // jQuery registers itself as a module. 'http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js', // Underscore registers itself as a module. 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.2.1/underscore-min.js' ], function() { // These nested require() calls are just due to how Backbone is built. Underscore basically says if require() // …