mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
improve #isEmpty implementation. add 2 tests
This commit is contained in:
@@ -60,6 +60,8 @@ $(document).ready(function() {
|
|||||||
ok(_.isEmpty([]), '[] is empty');
|
ok(_.isEmpty([]), '[] is empty');
|
||||||
ok(!_.isEmpty({one : 1}), '{one : 1} is not empty');
|
ok(!_.isEmpty({one : 1}), '{one : 1} is not empty');
|
||||||
ok(_.isEmpty({}), '{} is empty');
|
ok(_.isEmpty({}), '{} is empty');
|
||||||
|
ok(_.isEmpty(null), 'null is empty');
|
||||||
|
ok(_.isEmpty(), 'undefined is empty');
|
||||||
|
|
||||||
var obj = {one : 1};
|
var obj = {one : 1};
|
||||||
delete obj.one;
|
delete obj.one;
|
||||||
|
|||||||
@@ -503,7 +503,9 @@
|
|||||||
|
|
||||||
// Is a given array or object empty?
|
// Is a given array or object empty?
|
||||||
_.isEmpty = function(obj) {
|
_.isEmpty = function(obj) {
|
||||||
return _.keys(obj).length == 0;
|
if (_.isArray(obj)) return obj.length===0;
|
||||||
|
for (var k in obj) return false;
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is a given value a DOM element?
|
// Is a given value a DOM element?
|
||||||
|
|||||||
Reference in New Issue
Block a user