- Lo-Dash Essentials
- Adam Boduch
- 246字
- 2021-08-06 19:27:36
The difference between arrays and collections
One of the initial sources of confusion for newcomers to Lo-Dash is the distinction between arrays and collections. The Lo-Dash API has a set of functions for arrays, and a set of functions for collections. But why? It would appear that these functions are interchangeable for any collection. Well, a better definition of what a collection actually is according to Lo-Dash might clear things up.
A collection is an abstract concept. That is, we can use the collection functions found in Lo-Dash on any JavaScript object that we'd like to iterate over. For example, the forEach()
function will happily iterate over an array, a string, or an object. The subtle differences between these types, and what they mean when it comes to iterating, are hidden from the developer.
The array functions provided by Lo-Dash are less abstract, they do, in fact, expect an array. In a sense, even these functions are abstract because they don't explicitly check for the Array
type. They require that the object supports numerical indices and that it has a numerical length
property.
The takeaway is that, in the overwhelming majority of your days as a Lo-Dash programmer, the distinction between arrays and collections does not matter. Mainly, because the primary collection type will be an array anyway. In a small minority of cases, where the distinction does matter, just remember that the array functions have a slightly stricter criteria for what they consider acceptable data.
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發經典名著)
- Developing Mobile Web ArcGIS Applications
- C/C++算法從菜鳥到達人
- Vue.js快跑:構建觸手可及的高性能Web應用
- Production Ready OpenStack:Recipes for Successful Environments
- Blender 3D Incredible Machines
- 好好學Java:從零基礎到項目實戰
- Kivy Cookbook
- Cocos2d-x Game Development Blueprints
- Python Web自動化測試設計與實現
- Mastering Apache Camel
- Head First Kotlin程序設計
- Scratch編程從入門到精通
- Microsoft Windows Identity Foundation Cookbook
- 數據結構與算法詳解