mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Issue #123. _.extend shouldn't copy keys for undefined values.
This commit is contained in:
@@ -33,6 +33,8 @@ $(document).ready(function() {
|
|||||||
ok(_.isEqual(result, {x:'x', a:'a', b:'b'}), 'can extend from multiple source objects');
|
ok(_.isEqual(result, {x:'x', a:'a', b:'b'}), 'can extend from multiple source objects');
|
||||||
result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});
|
result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});
|
||||||
ok(_.isEqual(result, {x:2, a:'b'}), 'extending from multiple source objects last property trumps');
|
ok(_.isEqual(result, {x:2, a:'b'}), 'extending from multiple source objects last property trumps');
|
||||||
|
result = _.extend({}, {a: void 0, b: null});
|
||||||
|
equals(_.keys(result).join(''), 'b', 'extend does not copy undefined values');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("objects: defaults", function() {
|
test("objects: defaults", function() {
|
||||||
|
|||||||
@@ -543,7 +543,9 @@
|
|||||||
// Extend a given object with all the properties in passed-in object(s).
|
// Extend a given object with all the properties in passed-in object(s).
|
||||||
_.extend = function(obj) {
|
_.extend = function(obj) {
|
||||||
each(slice.call(arguments, 1), function(source) {
|
each(slice.call(arguments, 1), function(source) {
|
||||||
for (var prop in source) obj[prop] = source[prop];
|
for (var prop in source) {
|
||||||
|
if (source[prop] !== void 0) obj[prop] = source[prop];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
@@ -551,7 +553,9 @@
|
|||||||
// Fill in a given object with default properties.
|
// Fill in a given object with default properties.
|
||||||
_.defaults = function(obj) {
|
_.defaults = function(obj) {
|
||||||
each(slice.call(arguments, 1), function(source) {
|
each(slice.call(arguments, 1), function(source) {
|
||||||
for (var prop in source) if (obj[prop] == null) obj[prop] = source[prop];
|
for (var prop in source) {
|
||||||
|
if (obj[prop] == null) obj[prop] = source[prop];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user