罗短跑,数组和集合的区别 [英] Lo-Dash, difference between array and collection

查看:116
本文介绍了罗短跑,数组和集合的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在罗短跑文档一瞥表明API落入到分类:

A glance at the Lo-Dash docs shows that the API falls in to categories of:


  1. 阵列,

  2. 链接,

  3. 集合,

  4. 功能,

  5. 对象,

  6. 实用程序,

  7. 方法,

  8. 和属性

到阵列API更详细的研究表明,适用于阵列提供大约30个不同的方法。

A more detailed look in to the Arrays API shows approximately 30 different methods available that are applicable to arrays.

集合API具有比阵列的API几多个方法,并且它们不共享相同的方法。

The Collections API has a few more methods than the Arrays API, and they do not share the same methods.

内集合API,一个集合被描述为被迭代的对象,并可能是一个数组:

Within the Collections API, a collection is described as an object that is iterated, and may be an array:

集合(阵列|对象|字符串):集合遍历

collection (Array|Object|string): The collection to iterate over.

另外,有趣的是,有一个集合API方法 _的toArray 从集合返回一个数组:

Also, interestingly, there's a Collections API method _.toArray that returns an array from a collection:

参数

集合(阵列|对象|字符串):集合进行转换。返回

collection (Array|Object|string): The collection to convert. Returns

(阵列):返回新的转换阵列

(Array): Returns the new converted array.

会有人碰巧知道罗短跑API中的数组和集合之间的正式区别?我是presumption下,这是由于Backbone.js的差异,但是,现在我质疑我的推理为此,因为方法可能是其他地方。先谢谢了。

Would anyone happen to know a formal difference between an array and collection in the Lo-Dash API? I was under the presumption it was a difference due to Backbone.js, however, am now questioning my reasoning to that end, since the methods may be available elsewhere. Thanks in advance.

推荐答案

这是一个好主意,看看更详细的 Underscore.js文档,从中这种区别的。它指出:

It's a good idea to look at the more elaborate Underscore.js documentation, from which this distinction is derived. It states:

收集功能的数组,对象,如参数,NodeList的和类似的类似数组的对象。但它的工作原理是鸭打字,所以要避免传递对象以数字长度属性。

Collection functions work on arrays, objects, and array-like objects such as arguments, NodeList and similar. But it works by duck-typing, so avoid passing objects with a numeric length property.

基本上,集合是实现某种迭代界面的东西,他们在内部使用同一个迭代法(虽然Lodash源比下划线多一点令人费解)。所有收集方法做的工作都在数组和对象(和一些更多的东西可迭代),而阵列方法只应在阵列中使用(或也许一切与。长度和数字指标),而对象方法上的任何对象。

Basically, "collections" are things that implement some kind of "iterable" interface, and they internally use the same iteration method (though Lodash source is a bit more convoluted than Underscore). All the "collection methods" do work both on arrays and objects (and a few more iterable things), while the array methods should only be used on arrays (or maybe everything with .length and numeric indices), and the object methods work on any objects.

这篇关于罗短跑,数组和集合的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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