문제

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