Вопрос

It seems redundant to me that Backbone Collections have both a length property and size function that return the same result. Is there a reason for this?

Это было полезно?

Решение

One is the size of a particular backbone collection (the length property) the other is a method of the underscore library which can return the size of ANY collection = specifically useful for arrays, lists and anything else it might support.

It's here because all the methods are mixed into a Backbone collection as a convenience thing by the library. It should be noted that this is also a method call -- and not a computed property as well, so it would technically be slower as well to call size instead of just checking the maintained length.

In the interest of sticking with documented API(s) via Backbone itself, you are better off just using length

Другие советы

length is a property and will be available only on arrays type, where as size is a method and will be available in most data structure objects like Set, List, etcc..

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top