mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Cleanup previous commit.
This commit is contained in:
17
lodash.js
17
lodash.js
@@ -10255,21 +10255,22 @@
|
|||||||
var retUnwrapped = /^(?:first|last)$/.test(methodName);
|
var retUnwrapped = /^(?:first|last)$/.test(methodName);
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = arguments,
|
var value = this.__wrapped__,
|
||||||
|
args = arguments,
|
||||||
chainAll = this.__chain__,
|
chainAll = this.__chain__,
|
||||||
value = this.__wrapped__,
|
|
||||||
isLazy = value instanceof LazyWrapper,
|
isLazy = value instanceof LazyWrapper,
|
||||||
noQueue = !this.__queue__.length,
|
onlyLazy = isLazy && !this.__queue__.length;
|
||||||
unwrap = retUnwrapped && !chainAll;
|
|
||||||
|
|
||||||
if (unwrap && !isLazy) {
|
if (retUnwrapped && !chainAll) {
|
||||||
return lodash[methodName](this.value());
|
return onlyLazy
|
||||||
|
? func.call(value)
|
||||||
|
: lodash[methodName](this.value());
|
||||||
}
|
}
|
||||||
if (isLazy || isArray(value)) {
|
if (isLazy || isArray(value)) {
|
||||||
var wrapper = (isLazy && noQueue) ? value : new LazyWrapper(this),
|
var wrapper = onlyLazy ? value : new LazyWrapper(this),
|
||||||
result = func.apply(wrapper, args);
|
result = func.apply(wrapper, args);
|
||||||
|
|
||||||
return unwrap ? result : new LodashWrapper(result, chainAll);
|
return new LodashWrapper(result, chainAll);
|
||||||
}
|
}
|
||||||
return this.thru(function(value) {
|
return this.thru(function(value) {
|
||||||
var otherArgs = [value];
|
var otherArgs = [value];
|
||||||
|
|||||||
13
test/test.js
13
test/test.js
@@ -12703,13 +12703,18 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work when in a lazy chain sequence, before `.last`', 1, function() {
|
test('should work when in a lazy chain sequence before `first` or `last`', 1, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var actual = _([1, 2, 3]).map().xor([4]).last();
|
var wrapper = _([1, 2]).map().xor([2, 3]);
|
||||||
strictEqual(actual, 4);
|
|
||||||
|
var actual = _.map(['first', 'last'], function(methodName) {
|
||||||
|
return wrapper[methodName]();
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(actual, [1, 3]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}(1, 2, 3));
|
}(1, 2, 3));
|
||||||
|
|||||||
Reference in New Issue
Block a user