Lodash和Underscore.js之间的区别 [英] Differences between Lodash and Underscore.js

查看:230
本文介绍了Lodash和Underscore.js之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有人会选择 Lodash Underscore.js 实用程序库比其他实用程序库?

Why would someone prefer either the Lodash 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.

推荐答案

我创建了Lodash,以提供对数组,字符串,对象和arguments objects 1 的更一致的跨环境迭代支持.此后已成为Underscore.js的超集,提供了更一致的API行为,更多的功能(例如AMD支持,深度克隆,和深度合并),更全面的文档和单元测试(在 RingoJS 犀牛 PhantomJS ,和浏览器),更好的整体性能和针对大型数组/对象迭代的优化,以及自定义版本和模板预编译实用程序.

I created Lodash to provide more consistent cross-environment iteration support for arrays, strings, objects, and arguments objects1. It has since become a superset of Underscore.js, 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.js, RingoJS, 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.

由于Lodash的更新频率比Underscore.js的更新频率高,因此提供了lodash underscore内部版本 ,以确保与最新的稳定版本的Underscore.js.

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

有一次我什至得到了推送访问到Underscore.js,部分原因是Lodash负责提出30多个问题; Underscore.js v1.4.x +中的着陆错误修复,新功能和性能提升.

At one point I was even given push access to Underscore.js, in part because Lodash is responsible for raising more than 30 issues; landing bug fixes, new features, and performance gains in Underscore.js v1.4.x+.

此外,至少有三个 Backbone.js 样板,其中包括Lodash默认,Lodash现在在Backbone.js的官方文档中提到.

In addition, there are at least three Backbone.js boilerplates that include Lodash by default and Lodash is now mentioned in Backbone.js’s official documentation.

查看Kit Cambridge的帖子 ,以更深入地了解Lodash和Underscore.js之间的区别.

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

脚注:

  1. Underscore.js对数组,字符串,对象和arguments对象的支持不一致.在较新的浏览器中,Underscore.js方法会忽略数组中的孔,对象"方法迭代arguments对象,将字符串视为类似于数组的方法,而方法则在较旧的版本中正确地迭代函数(忽略其原型"属性)和对象(迭代带有阴影的属性,例如"toString"和"valueOf")浏览器,他们不会.此外,Underscore.js方法(如_.clone)可保留数组中的孔,而其他方法(如_.flatten)则不保留.
  1. Underscore.js has inconsistent support for arrays, strings, objects, and arguments objects. In newer browsers, Underscore.js 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.js methods, like _.clone, preserve holes in arrays, while others like _.flatten don't.

这篇关于Lodash和Underscore.js之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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