Add more _.omit benchmarks and update Underscore.

Former-commit-id: b8de29706b381ebc000a7cbaa19aa0a2a628d6a8
This commit is contained in:
John-David Dalton
2012-08-25 01:04:33 -07:00
parent c7f290f42e
commit 0e4afefc7f
4 changed files with 89 additions and 19 deletions

View File

@@ -698,17 +698,22 @@
// Return a copy of the object only containing the whitelisted properties.
_.pick = function(obj) {
var result = {};
each(_.flatten(slice.call(arguments, 1)), function(key) {
if (key in obj) result[key] = obj[key];
var copy = {};
var keys = _.flatten(slice.call(arguments, 1));
each(keys, function(key) {
if (key in obj) copy[key] = obj[key];
});
return result;
return copy;
};
// Return a copy of the object without the blacklisted properties.
_.omit = function(obj) {
var copy = _.extend({}, obj);
var keys = _.flatten(slice.call(arguments, 1));
return _.pick(obj, _.difference(_.keys(obj), keys));
each(keys, function(key) {
delete copy[key];
});
return copy;
};
// Fill in a given object with default properties.