如果您不使用“export” Backbone,那么您将无法在模块中获取到 Backbone(window.Backbone) 的语言环境引用,该引用在主干.js 中定义。
//without export Backbone
shim : {
'bbn':{
//exports:'Backbone',
deps:['underscore']
},
'underscore': {
exports: '_'
}
};
require(['bbn'], function(localBackbone) {
//localBackbone undefined.
console.log('localBackbone:,' localBackbone);
});
RequireJs 解释如下:
//RequireJS will use the shim config to properly load 'backbone' and give a local
//reference to this module. The global Backbone will still exist on
//the page too.
define(['backbone'], function (Backbone) {
return Backbone.Model.extend({});
});
RequireJS 将使用 shim 配置来获取全局 Backbone
function getGlobal(value) {
if (!value) {
return value;
}
var g = global;
each(value.split('.'), function (part) {
g = g[part];
});
return g;
}