2012-05-31 41 views
7

我使用require.version“2.0.0”
我想获得下划线作为一个局部变量:Requirejs,在加载库问题突出

这里是我的代码(1)。

为什么_未定义?
我怎样才能得到_里面的功能就像一个局部变量


(1)

require.config({ 
    baseUrl: "./", 
    paths: { 
     'underscore': 'vendor/js/underscore-min' 
    }, 
    shim: { 
     'underscore': { 
      exports: 'underscore' 
     } 
    } 
}); 

require([ 
    'underscore' 
], function(_) { 
    "use strict"; 
    console.log(_); // undefined 
}); 
+1

您是否使用Underscore的https分支https://github.com/amdjs/underscore?如果没有,这可以解释您的问题 – nikoshr

+0

@nikoshr感谢您的评论。我没有使用Underscore的AMD分支。无论如何有没有办法解决这个问题,而不使用AMD版本? –

+0

@nikoshr无论如何,如果你看这[文章](http://tbranyen.com/post/amdrequirejs-shim-plugin-for-loading-incompatible-javascript)似乎垫片已被引入修复非AMD插件。 –

回答

5

那么,就由exports: '_'更换exports: 'underscore'。 这说明需要附加到_模块。所以参考文献window._仍然有效。