documentcloud/underscore — pull request #799 by afeld (2012-09-27 09:11:29+00:00)
Title: better handling of Collection types

When working on [Backbone-Nested]() I noticed that I wasn't able to iterate over an object with a `length` property set to an arbitrary value, which is present in [the Backbone tests](https://github.com/documentcloud/backbone/blob/0.9.2/test/model.js#L20).

```javascript
_.each({length: 20}, function(){ /* never reached */ });
```

`_.each()` and `_.size()` were handing this case incorrectly, and `_.isEmpty()` was additionally giving incorrect results for Arguments, HTMLCollections, NodeLists and jQuery Array-likes. I have added `_.isArrayLike()` so that these methods (which all depend on `.length`) can detect the types in a central place.

Tests are green in Chrome 22, FF 15 and Safari 6.0. I did some testing in various IE versions as I went but used up my [Browserstack](http://www.browserstack.com/) limit, so if others wouldn't mind verifying (particularly v6-8), that would be appreciated. Thanks!