为什么 Underscore.js 取消了对 AMD 的支持?

发布于 2024-12-28 20:40:38 字数 306 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜司空 2025-01-04 20:40:38

Jeremy提交的评论

是的。不支持特定的脚本加载器肯定会让它们更容易全部正常工作。

对于首先合并支持,我深表歉意。

他还推文更多关于这一变化(链接来自稍后的评论):

...因为 AMD 支持正在破坏也恰好使用 Require.js 的页面上的常规下划线嵌入...

Jeremy gave his reasoning in the comments of the commit:

Yep. Not supporting a particular script loader will definitely make it easier for all of them to work properly.

I apologize for merging the support in the first place.

He also tweeted a 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 …

往事随风而去 2025-01-04 20:40:38

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.

心头的小情儿 2025-01-04 20:40:38

我觉得有必要补充一下这个相当老的问题。

Backbone 和 Underscore 现在都支持 AMD

  1. Underscore 提交
  2. Backbone Commit

讨论(尽管 Backbone 的讨论有点令人费解,因为讨论的语气与实际情况之间存在明显的差异)结果):

  1. 下划线问题
  2. 骨干问题

I felt the need to add to this fairly old question.

Both Backbone and Underscore now support AMD:

  1. Underscore commit
  2. Backbone Commit

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):

  1. Underscore Issue
  2. Backbone Issue
熊抱啵儿 2025-01-04 20:40:38

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文