Permalink
Browse files

fixes #1505: _.omit can't take non-string property names

  • Loading branch information...
1 parent b38e8cb commit a315e9f4473005a8310540b16d565519a9556106 @michaelficarra michaelficarra committed Mar 6, 2014
Showing with 6 additions and 2 deletions.
  1. +4 −0 test/objects.js
  2. +2 −2 underscore.js
View
@@ -70,6 +70,8 @@
deepEqual(result, {b: 2, c: 3}, 'can restrict properties to those named in an array');
result = _.pick({a: 1, b: 2, c: 3}, ['a'], 'b');
deepEqual(result, {a: 1, b: 2}, 'can restrict properties to those named in mixed args');
+ result = _.pick(['a', 'b'], 1);
+ deepEqual(result, {1: 'b'}, 'can pick numeric properties');
var data = {a: 1, b: 2, c: 3};
var callback = function(value, key, object) {
@@ -93,6 +95,8 @@
deepEqual(result, {b: 2}, 'can omit several named properties');
result = _.omit({a: 1, b: 2, c: 3}, ['b', 'c']);
deepEqual(result, {a: 1}, 'can omit properties named in an array');
+ result = _.omit(['a', 'b'], 0);
+ deepEqual(result, {1: 'b'}, 'can omit numeric properties');
var data = {a: 1, b: 2, c: 3};
var callback = function(value, key, object) {
View
@@ -887,7 +887,7 @@
if (iterator.call(context, value, key, obj)) result[key] = value;
}
} else {
- var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
+ var keys = concat.apply([], slice.call(arguments, 1));
for (var i = 0, length = keys.length; i < length; i++) {
var key = keys[i];
if (key in obj) result[key] = obj[key];
@@ -902,7 +902,7 @@
if (_.isFunction(iterator)) {
iterator = _.negate(iterator);
} else {
- keys = concat.apply(ArrayProto, slice.call(arguments, 1));
+ keys = _.map(concat.apply([], slice.call(arguments, 1)), function(o){ return '' + o; });
@megawac

megawac Mar 6, 2014

Collaborator

I think _.map(concat.apply(ArrayProto, slice.call(arguments, 1)), String) would work

iterator = function(value, key) { return !_.contains(keys, key); };
}
return _.pick(obj, iterator, context);

0 comments on commit a315e9f

Please sign in to comment.