Make _.wrap use _.identity when wrapper is nullish. [closes #767]

This commit is contained in:
John-David Dalton
2014-11-06 23:15:48 -08:00
parent d7b0e66270
commit c3a5b12cd3
2 changed files with 16 additions and 4 deletions

View File

@@ -6936,6 +6936,7 @@
* // => '<p>fred, barney, &amp; pebbles</p>' * // => '<p>fred, barney, &amp; pebbles</p>'
*/ */
function wrap(value, wrapper) { function wrap(value, wrapper) {
wrapper = wrapper == null ? identity : wrapper;
return createWrapper(wrapper, PARTIAL_FLAG, null, [value]); return createWrapper(wrapper, PARTIAL_FLAG, null, [value]);
} }

View File

@@ -12458,6 +12458,18 @@
var object = { 'p': p, 'text': 'fred, barney, & pebbles' }; var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
strictEqual(object.p(), '<p>fred, barney, &amp; pebbles</p>'); strictEqual(object.p(), '<p>fred, barney, &amp; pebbles</p>');
}); });
test('should use `_.identity` when `wrapper` is nullish', 1, function() {
var values = [, null, undefined],
expected = _.map(values, _.constant('a'));
var actual = _.map(values, function(value, index) {
var wrapped = index ? _.wrap('a', value) : _.wrap('a');
return wrapped('b', 'c');
});
deepEqual(actual, expected);
});
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@@ -13227,13 +13239,12 @@
'rearg', 'rearg',
'tap', 'tap',
'throttle', 'throttle',
'thru', 'thru'
'wrap'
]; ];
var acceptFalsey = _.difference(allMethods, rejectFalsey); var acceptFalsey = _.difference(allMethods, rejectFalsey);
test('should accept falsey arguments', 197, function() { test('should accept falsey arguments', 198, function() {
var emptyArrays = _.map(falsey, _.constant([])), var emptyArrays = _.map(falsey, _.constant([])),
isExposed = '_' in root, isExposed = '_' in root,
oldDash = root._; oldDash = root._;
@@ -13299,7 +13310,7 @@
}); });
}); });
test('should throw a TypeError for falsey arguments', 22, function() { test('should throw a TypeError for falsey arguments', 21, function() {
_.each(rejectFalsey, function(methodName) { _.each(rejectFalsey, function(methodName) {
var expected = _.map(falsey, _.constant(true)), var expected = _.map(falsey, _.constant(true)),
func = _[methodName]; func = _[methodName];