【发布时间】:2014-11-04 12:22:58
【问题描述】:
我们可以使用 AMD 兼容版本的 BackboneJS 和 UnderscoreJS
我查看了两者的 AMD 兼容库 (https://github.com/amdjs/),下面是使它们与 AMD 兼容的相关代码。
BackboneJS (AMD);
else if (typeof define === 'function' && define.amd) {
// AMD
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
root.Backbone = factory(root, exports, _, $);
});
下划线JS(AMD);
// AMD define happens at the end for compatibility with AMD loaders
// that don't enforce next-turn semantics on modules.
if (typeof define === 'function' && define.amd) {
define('underscore', function() {
return _;
});
}
现在要在我们的代码中使用这些 AMD 兼容库,我们说:
requirejs.config({
enforceDefine: true,
paths: {
"jquery": "libs/jquery-1.8.3",
"underscore": "libs/underscore-amd",
"backbone": "libs/backbone-amd"
}
});
现在我读到骨干模块的名称可以是任何名称,但下划线的名称必须是“下划线”,对于下划线,大写很重要。
为什么会根据库的定义方式有所不同?
【问题讨论】:
标签: javascript backbone.js requirejs underscore.js js-amd