问题描述
为什么有人更喜欢或实用程序库超过另一个吗?
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,为数组,字符串,对象和参数提供了更一致的跨环境迭代支持
对象。它已成为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
objects. 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.
一度我甚至给了。
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和Underscore之间的差异。
Check out Kit Cambridge's post, Say "Hello" to Lo-Dash, for a deeper breakdown on the differences between Lo-Dash and Underscore.
脚注:
- Underscore对数组,字符串,对象和
参数
对象的支持不一致。在较新的浏览器中,Underscore方法忽略了,对象方法迭代参数
对象,字符串被视为类似数组,方法正确迭代函数(忽略它们的原型属性)和对象(迭代阴影属性,如toString和 valueOf),而在较旧的浏览器中,他们不会。此外,像_。clone
这样的Underscore方法会保留数组中的漏洞,而其他类似_。flatten
则不会。 / li>
- Underscore has inconsistent support for arrays, strings, objects, and
arguments
objects. In newer browsers, Underscore methods ignore holes in arrays, "Objects" methods iteratearguments
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和下划线之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!