Issue #123. _.extend shouldn't copy keys for undefined values.

This commit is contained in:
Jeremy Ashkenas
2011-04-15 17:46:16 -04:00
parent bf214d2c8d
commit ea44179d81
2 changed files with 8 additions and 2 deletions

View File

@@ -543,7 +543,9 @@
// Extend a given object with all the properties in passed-in object(s).
_.extend = function(obj) {
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;
};
@@ -551,7 +553,9 @@
// Fill in a given object with default properties.
_.defaults = function(obj) {
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;
};