Skip to content

Commit

Permalink
Even though it's not really part of the API, making _.isEmpty work wi…
Browse files Browse the repository at this point in the history
…th Strings cross-browser.
  • Loading branch information
jashkenas committed Apr 6, 2010
1 parent f0427da commit 79f65b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/objects.js
Expand Up @@ -69,6 +69,8 @@ $(document).ready(function() {
ok(_.isEmpty(new RegExp('')), 'objects with prototype properties are empty');
ok(_.isEmpty(null), 'null is empty');
ok(_.isEmpty(), 'undefined is empty');
ok(_.isEmpty(''), 'the empty string is empty');
ok(!_.isEmpty('moe'), 'but other strings are not');

var obj = {one : 1};
delete obj.one;
Expand Down
2 changes: 1 addition & 1 deletion underscore.js
Expand Up @@ -491,7 +491,7 @@

// Is a given array or object empty?
_.isEmpty = function(obj) {
if (_.isArray(obj)) return obj.length === 0;
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
return true;
};
Expand Down

0 comments on commit 79f65b4

Please sign in to comment.