enhance #extend to allow taking multiple source objects.

This is done in jquery, extjs, and others as well.

added tests, no docs
This commit is contained in:
Mike Frawley
2010-01-24 11:53:30 -06:00
committed by Jeremy Ashkenas
parent 8c6694c242
commit 4085b68be4
2 changed files with 15 additions and 7 deletions

View File

@@ -432,10 +432,13 @@
return _.filter(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort();
};
// Extend a given object with all of the properties in a source object.
_.extend = function(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
// Extend a given object with all the properties in given object(s)
_.extend = function(obj) {
var prop;
each(_.rest(arguments), function (source) {
for (prop in source) obj[prop] = source[prop];
});
return obj;
};
// Create a (shallow-cloned) duplicate of an object.