lodash和下划线之间的差异 [英] Differences between lodash and underscore

查看:286
本文介绍了lodash和下划线之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有人更喜欢 lodash.js underscore.js 实用程序库超过另一个吗?

Why would someone prefer either the lodash.js or underscore.js utility library over the other?

Lodash似乎是下划线的直接替代品,后者已经存在更长时间。

Lodash seems to be a drop-in replacement for underscore, the latter having been around longer.

我认为两者都很棒,但我对他们如何进行有根据的比较工作知之甚少,我想更多地了解这些差异。

I think both are brilliant, but I do not know enough about how they work to make an educated comparison, and I would like to know more about the differences.

推荐答案

我创建了Lo-Dash,为数组,字符串,对象和参数提供了更一致的跨环境迭代支持对象 1 。它已成为Underscore的超集,提供更一致的API行为,更多功能(如AMD支持,深度克隆和深度合并),更全面的文档和单元测试(在Node,Ringo,Rhino,Narwhal,PhantomJS和浏览器),更好的整体性能和大型数组/对象迭代的优化,以及自定义构建和模板预编译的更大灵活性实用程序。

I created Lo-Dash to provide more consistent cross-environment iteration support for arrays, strings, objects, and arguments objects1. It has since become a superset of Underscore, providing more consistent API behavior, more features (like AMD support, deep clone, and deep merge), more thorough documentation and unit tests (tests which run in Node, Ringo, Rhino, Narwhal, PhantomJS, and browsers), better overall performance and optimizations for large arrays/object iteration, and more flexibility with custom builds and template pre-compilation utilities.

因为Lo-Dash比Underscore更频繁更新, lodash下划线 build 提供以确保与最新稳定版本的Underscore兼容。

Because Lo-Dash is updated more frequently than Underscore, a lodash underscore build is provided to ensure compatibility with the latest stable version of Underscore.

一度我甚至给了 push acces对于Underscore,部分是因为Lo-Dash负责筹集超过30个问题;登陆错误修复,新功能,& Underscore v1.4.x +中的perf增益。

At one point I was even given push access to Underscore, in part because Lo-Dash is responsible for raising more than 30 issues; landing bug fixes, new features, & perf gains in Underscore v1.4.x+.

此外,至少有3个Backbone样板,默认情况下包含Lo-Dash,现在Backbone中提到了Lo-Dash官方文档

In addition there are at least 3 Backbone boilerplates that include Lo-Dash by default and Lo-Dash is now mentioned in Backbone’s official documentation.

查看Kit剑桥的帖子, 说你好对于Lo-Dash ,可以更深入地分析Lo-Dash和Underscore之间的差异。

Check out Kit Cambridge's post, Say "Hello" to Lo-Dash, for a deeper breakdown on the differences between Lo-Dash and Underscore.

脚注:


  1. Underscore对数组,字符串,对象和参数对象的支持不一致。在较新的浏览器中,Underscore方法忽略了数组中的漏洞,对象方法迭代参数对象,字符串被视为类似数组,方法正确迭代函数(忽略它们的原型属性)和对象(迭代阴影属性,如toString和 valueOf),而在较旧的浏览器中,他们不会。此外,像 _。clone 这样的Underscore方法会保留数组中的漏洞,而其他类似 _。flatten 则不会。 / li>
  1. Underscore has inconsistent support for arrays, strings, objects, and arguments objects. In newer browsers, Underscore methods ignore holes in arrays, "Objects" methods iterate arguments objects, strings are treated as array-like, and methods correctly iterate functions (ignoring their "prototype" property) and objects (iterating shadowed properties like "toString" and "valueOf"), while in older browsers they will not. Also, Underscore methods like _.clone preserve holes in arrays, while others like _.flatten don't.

这篇关于lodash和下划线之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆