Merge pull request #523 from chrisleishman/restrict

Add _.restrict(source, *keys)
This commit is contained in:
Jeremy Ashkenas
2012-04-02 11:51:56 -07:00
3 changed files with 33 additions and 0 deletions

View File

@@ -648,6 +648,16 @@
return obj;
};
// Restrict a given object to the properties named
_.restrict = function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var dest = {};
each(_.flatten(slice.call(arguments, 1)), function(prop) {
if (prop in obj) dest[prop] = obj[prop];
});
return dest;
};
// Fill in a given object with default properties.
_.defaults = function(obj) {
each(slice.call(arguments, 1), function(source) {