为什么 Underscore.js 取消了对 AMD 的支持?
1.3.0 — 2012 年 1 月 11 日从 Underscore 中删除了 AMD (RequireJS) 支持。如果您想将 Underscore 与 RequireJS 一起使用,您可以将其作为普通脚本加载、包装或修补您的副本,或者下载分叉版本。
他们为什么这么做?有谁知道吗?因为他们是在几个月前(10 月份)才添加的,而且据说 AMD(异步模块定义)远优于 CommonJS 模块。
更新:自 2013 年 12 月起,此功能已再次得到支持。
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.
Why have they done it? Does anyone know? Because they added it only few month ago (in October), and AMD (Asynchronous Module Definition) is said to be far superior to CommonJS modules.
Update: As of December 2013, this has been supported again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Jeremy 在 提交的评论:
他还推文更多关于这一变化(链接来自稍后的评论):
Jeremy gave his reasoning in the comments of the commit:
He also tweeted a bit more on the change (link from a later comment):
Underscore 的开发人员认为,支持 AMD 会破坏对非 AMD 启用脚本的支持。实际上并非如此,因为您可以拥有一个既支持 AMD 又可以在非 AMD 部署上按原样运行的脚本。
现在有 Underscore 的直接替代品:Lo-Dash。其中,以及 Underscore 中没有的其他功能,包括 AMD/非 AMD 双重性。
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 can have a script that is both AMD-enabled but also works as-is on a non-AMD deployment.
There is now a drop-in replacement for Underscore: Lo-Dash. Which, along with other features not in Underscore, includes AMD/non-AMD duality.
我觉得有必要补充一下这个相当老的问题。
Backbone 和 Underscore 现在都支持 AMD:
讨论(尽管 Backbone 的讨论有点令人费解,因为讨论的语气与实际情况之间存在明显的差异)结果):
I felt the need to add to this fairly old question.
Both Backbone and Underscore now support 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):
ES5-shim 提供了许多与下划线和 lodash 相同的功能(array.forEach()、array .map() 等)。
ES5-shim 本身支持 AMD,与 underscore 和 lodash 不同,它不会添加浏览器可能已经提供的内容的额外副本。相反,它向旧版浏览器添加了原生 ES5 功能。
当 IE8 和其他旧版浏览器淘汰时,您可以简单地删除 ES5-shim 依赖项,而无需像使用 lodash 或 underscore 那样移植代码。
ES5-shim provides many of the same features as underscore and lodash (array.forEach(), array.map() etc).
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.
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.