Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
936 views
in Technique[技术] by (71.8m points)

underscore.js - lodash和下划线之间的差异[关闭](Differences between lodash and underscore [closed])

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

(为什么有人更喜欢lodash.jsunderscore.js实用程序库而不是另一个?)

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

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

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.

(我认为两者都很精彩,但我对他们如何努力进行有根据的比较并不了解,我想更多地了解这些差异。)

  ask by Brian M. Hunt translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I created Lo-Dash to provide more consistent cross-environment iteration support for arrays, strings, objects, and arguments objects 1 .

(我创建了Lo-Dash,为数组,字符串,对象和arguments对象1提供更一致的跨环境迭代支持。)

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.

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

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.

(由于Lo-Dash比lodash underscore更新频繁, 因此提供lodash underscore构建以确保与最新稳定版本的lodash underscore兼容。)

At one point I was even given push access to Underscore, in part because Lo-Dash is responsible for raising more than 30 issues;

(有一次,我甚至获得了对Underscore的推动 ,部分原因是Lo-Dash负责筹集超过30个问题;)

landing bug fixes, new features, & perf gains in Underscore v1.4.x+.

(Underscore v1.4.x +中的登陆错误修复,新功能和性能提升。)

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 .

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

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

(查看Kit Cambridge的帖子, 向Lo-Dash说“你好” ,以便更深入地分析Lo-Dash和Underscore之间的差异。)

Footnotes:

(脚注:)

  1. Underscore has inconsistent support for arrays, strings, objects, and arguments objects.

    (Underscore对数组,字符串,对象和arguments对象的支持不一致。)

    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.

    (在较新的浏览器中,Underscore方法忽略数组中的漏洞 ,“Objects”方法迭代arguments对象,字符串被视为类似数组,方法正确迭代函数(忽略它们的“原型”属性)和对象(迭代阴影属性,如“toString”)和“valueOf”),而在较旧的浏览器中他们不会。)

    Also, Underscore methods like _.clone preserve holes in arrays, while others like _.flatten don't.

    (此外,像_.clone这样的_.clone方法_.clone保留数组中的漏洞,而像_.flatten这样的其他_.flatten则不会。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...