我正在尝试使用/UnderscoreJS 1.7.0加载RequireJS 2.1.14-3. 在我的应用程序启动时,UnderscoreJS 加载良好,但它是“未定义的”。请参阅下面的详细信息:
main.js
define(function() {
// Configuration of RequireJS
requirejs.config({
enforceDefine : true,
map : {
'*': {
...
'underscore' : 'webjars/underscorejs/1.7.0/underscore'
},
},
// The base URL is just the top-level directory where the files are stored
baseUrl : './',
// Kick-start the application by loading these files
deps : [ 'MyPanel' ],
});
});
使用它的模块:
define(['ractive',
'underscore',
...],
function(Ractive,
_,
...){
var Foo = Ractive.extend({
...
oninit: function(){
var anArray = [1, 2, 3]
_.each(anArray, function(item){
...
})
}
}
浏览器控制台中的结果:

underscoreJS 文件由浏览器加载:

这必须是一个细节,但我使用和管理我的Javascript依赖项mavenwebjars
那为什么是我的_ undefined?