javascript 为什么 Underscore.js 取消了对 AMD 的支持?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9009510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why did Underscore.js remove support for AMD?
提问by c69
1.3.0 — Jan. 11, 2012 Removed AMD (RequireJS) support from Underscore. If you'd like to use Underscore with RequireJS, you can load it as a normal script, wrap or patch your copy, or download a forked version.
1.3.0 — 2012 年 1 月 11 日从 Underscore 中删除了 AMD (RequireJS) 支持。如果您想将 Underscore 与 RequireJS 一起使用,您可以将其作为普通脚本加载,包装或修补您的副本,或者下载分叉版本。
Why have they done it? Does anyone know? Because they added it only few month ago (in October), and AMD (Asynchronous Module Definition) is saidto be far superior to CommonJS modules.
他们为什么这样做?有人知道吗?因为他们在几个月前(10 月)才添加了它,并且据说AMD(异步模块定义)远远优于 CommonJS 模块。
Update: As of December 2013, this has been supported again.
更新:截至 2013 年 12 月,已再次支持此功能。
采纳答案by Jonathan Lonowski
Jeremygave his reasoning in the comments of the commit:
Yep. Not supporting a particular script loader will definitely make it easier for allof them to work properly.
I apologize for merging the support in the first place.
是的。不支持特定的脚本装载机肯定将使它更容易为所有他们的正常工作。
我很抱歉首先合并支持。
He also tweeteda bit more on the change (link from a later comment):
他还在推特上发布了更多关于更改的推文(链接来自后来的评论):
… because AMD support is breaking regular Underscore embeds on pages that also happen to use Require.js …
……因为 AMD 的支持打破了页面上的常规 Underscore 嵌入,这些页面也碰巧使用了 Require.js ……
回答by Angelos Pikoulas
The developers of Underscore thought that having AMD support would break support on non-AMD enabled scripts. This is actually not the case, as you canhave a script that is both AMD-enabled but also works as-is on a non-AMD deployment.
Underscore 的开发人员认为拥有 AMD 支持会破坏对非 AMD 启用脚本的支持。实际上并非如此,因为您可以拥有一个既支持 AMD 又在非 AMD 部署上按原样运行的脚本。
There is now a drop-in replacement for Underscore: Lo-Dash. Which, along with other features not in Underscore, includes AMD/non-AMD duality.
现在有一个 Underscore 的替代品:Lo-Dash。其中,连同 Underscore 中没有的其他功能,包括 AMD/非 AMD 双重性。
回答by ZenMaster
I felt the need to add to this fairly old question.
我觉得有必要补充这个相当古老的问题。
Both Backbone and Underscore now support AMD:
Backbone 和 Underscore 现在都支持 AMD:
Discussions (albeit Backbone's one is a bit puzzling as there is a clear discrepancy between the tone of the discussion and the actual outcome):
讨论(尽管 Backbone 的讨论有点令人费解,因为讨论的基调与实际结果之间存在明显差异):
回答by mikemaccana
ES5-shimprovides many of the same features as underscore and lodash (array.forEach(), array.map() etc).
ES5-shim提供了许多与下划线和 lodash 相同的特性(array.forEach()、array.map() 等)。
ES5-shim natively supports AMD, unlike underscore and lodash, doesn't add extra copies of things your browser probably already provides. Rather it adds native ES5 features to older browsers.
ES5-shim 原生支持 AMD,与 underscore 和 lodash 不同,它不会添加浏览器可能已经提供的内容的额外副本。相反,它为旧版浏览器添加了原生 ES5 功能。
When IE8 and other older browsers die out, you can simply remove the ES5-shim dependency without having to port code like you would with lodash or underscore.
当 IE8 和其他旧浏览器消亡时,您可以简单地删除 ES5-shim 依赖项,而无需像使用 lodash 或下划线那样移植代码。