mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Fix deferred chaining test fails.
This commit is contained in:
41
lodash.js
41
lodash.js
@@ -9641,25 +9641,19 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// add `Array` functions that return the existing wrapped value
|
// add `Array` functions that return wrapped value
|
||||||
arrayEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) {
|
arrayEach(['concat', 'push', 'reverse', 'sort', 'splice', 'unshift'], function(methodName) {
|
||||||
var func = arrayProto[methodName];
|
var func = arrayProto[methodName],
|
||||||
|
retVal = methodName == 'concat' || methodName == 'splice';
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
return this.tap(function(value) {
|
return this[retVal ? 'thru' : 'tap'](function(value) {
|
||||||
func.apply(value, args);
|
return func.apply(value, args);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// add `Array` functions that return new wrapped values
|
|
||||||
arrayEach(['concat', 'splice'], function(methodName) {
|
|
||||||
var func = arrayProto[methodName];
|
|
||||||
lodash.prototype[methodName] = function() {
|
|
||||||
return new lodashWrapper(func.apply(this.value(), arguments), this.__chain__);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// avoid array-like object bugs with `Array#shift` and `Array#splice`
|
// avoid array-like object bugs with `Array#shift` and `Array#splice`
|
||||||
// in IE < 9, Firefox < 10, Narwhal, and RingoJS
|
// in IE < 9, Firefox < 10, Narwhal, and RingoJS
|
||||||
if (!support.spliceObjects) {
|
if (!support.spliceObjects) {
|
||||||
@@ -9667,14 +9661,23 @@
|
|||||||
var func = arrayProto[methodName],
|
var func = arrayProto[methodName],
|
||||||
isSplice = methodName == 'splice';
|
isSplice = methodName == 'splice';
|
||||||
|
|
||||||
|
function process(value, args) {
|
||||||
|
var result = func.apply(value, args);
|
||||||
|
if (value.length === 0) {
|
||||||
|
delete value[0];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = arguments;
|
var args = arguments,
|
||||||
|
chainAll = this.__chain__;
|
||||||
|
|
||||||
|
if (!chainAll && !isSplice) {
|
||||||
|
return process(this.value(), args);
|
||||||
|
}
|
||||||
return this[isSplice ? 'thru' : 'tap'](function(value) {
|
return this[isSplice ? 'thru' : 'tap'](function(value) {
|
||||||
var result = func.apply(value, args);
|
return process(value, args);
|
||||||
if (value.length === 0) {
|
|
||||||
delete value[0];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11823,7 +11823,7 @@
|
|||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var wrapped = _({ '0': 1, 'length': 1 });
|
var wrapped = _({ '0': 1, 'length': 1 });
|
||||||
if (methodName == 'splice') {
|
if (methodName == 'splice') {
|
||||||
wrapped.splice(0, 1);
|
wrapped.splice(0, 1).value();
|
||||||
} else {
|
} else {
|
||||||
wrapped[methodName]();
|
wrapped[methodName]();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user