isEmpty check for lenght === 0 in any object with lenght property#690
isEmpty check for lenght === 0 in any object with lenght property#690marioizquierdo wants to merge 1 commit into
Conversation
… you can do things like _.isEmpty(jQuery(selector));
|
If the
This function deals with objects and their properties, not arrays or array-like objects and their members. |
|
Just for curiosity, it would be nice to have a broken test, or at least an example here as where checking for length === 0 is not OK. |
See line 830. The |
|
I guess the point here is this: Underscore current version: Pull request 690 (after this pull request): This is not covered in the test suite. |
|
FWIW, this patch would break the usage of _.isEmpty({}); // -> true
_.isEmpty({length: 0}); // -> false |
Apply some duck typing ruby-style checks, and now isEmpty behavior is more intuitive.
Now you can do things like this (that is not true with the current implementation):
In general, makes sense to think that anything with length === 0 is empty.