From db97ae46e5bacc14c68f8666542193d448cf7a64 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 14 Nov 2014 19:36:52 -0800 Subject: [PATCH] Cleanup lazy `_.pluck` and `_.where`. --- lodash.js | 6 +++--- test/test.js | 41 +++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lodash.js b/lodash.js index 55246781f..2a69d2452 100644 --- a/lodash.js +++ b/lodash.js @@ -10190,13 +10190,13 @@ }; }); - // add `LazyWrapper` methods for `_.pluck` and `_.where` + // Add `LazyWrapper` methods for `_.pluck` and `_.where`. arrayEach(['pluck', 'where'], function (methodName, index) { var operationName = index ? 'filter' : 'map', getCallback = index ? matches : property; - LazyWrapper.prototype[methodName] = function (arg) { - return this[operationName](getCallback(arg)); + LazyWrapper.prototype[methodName] = function(value) { + return this[operationName](getCallback(value)); }; }); diff --git a/test/test.js b/test/test.js index 14e8b6081..d87fa879d 100644 --- a/test/test.js +++ b/test/test.js @@ -9291,19 +9291,6 @@ deepEqual(_.pluck(objects, 'a'), [1, undefined, undefined, 4]); }); - test('should work in a lazy chain sequence', 1, function () { - if (!isNpm) { - var array = [{prop: 1}, null, {prop: 3}, {prop: 4}]; - - var wrapped = _(array).filter(Boolean).pluck("prop"); - - deepEqual(wrapped.value(), [1, 3, 4]); - } - else { - skipTest(); - } - }); - test('should coerce `key` to a string', 1, function() { function fn() {} fn.toString = _.constant('fn'); @@ -9317,6 +9304,21 @@ deepEqual(actual, [[1], [2], [3], [4]]); }); + + test('should work in a lazy chain sequence', 2, function() { + if (!isNpm) { + var array = [{ 'a': 1 }, null, { 'a': 3 }, { 'a': 4 }], + actual = _(array).pluck('a').value(); + + deepEqual(actual, [1, undefined, 3, 4]); + + actual = _(array).filter(Boolean).pluck('a').value(); + deepEqual(actual, [1, 3, 4]); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -12516,17 +12518,16 @@ deepEqual(actual, expected); }); - test('should work in a lazy chain sequence', 1, function () { + test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { var array = [ - {'a': 1}, - {'a': 3}, - {'a': 1, 'b': 2} + { 'a': 1 }, + { 'a': 3 }, + { 'a': 1, 'b': 2 } ]; - var wrapped = _(array).where({'a': 1}); - - deepEqual(wrapped.value(), [array[0], array[2]]); + var actual = _(array).where({ 'a': 1 }).value(); + deepEqual(actual, [array[0], array[2]]); } else { skipTest();