Fix deferred chaining test fails.

This commit is contained in:
John-David Dalton
2014-09-11 23:36:12 -07:00
parent 1fe9ba5879
commit ad203e1461
2 changed files with 23 additions and 20 deletions

View File

@@ -9641,25 +9641,19 @@
};
});
// add `Array` functions that return the existing wrapped value
arrayEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) {
var func = arrayProto[methodName];
// add `Array` functions that return wrapped value
arrayEach(['concat', 'push', 'reverse', 'sort', 'splice', 'unshift'], function(methodName) {
var func = arrayProto[methodName],
retVal = methodName == 'concat' || methodName == 'splice';
lodash.prototype[methodName] = function() {
var args = arguments;
return this.tap(function(value) {
func.apply(value, args);
return this[retVal ? 'thru' : 'tap'](function(value) {
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`
// in IE < 9, Firefox < 10, Narwhal, and RingoJS
if (!support.spliceObjects) {
@@ -9667,14 +9661,23 @@
var func = arrayProto[methodName],
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() {
var args = arguments;
var args = arguments,
chainAll = this.__chain__;
if (!chainAll && !isSplice) {
return process(this.value(), args);
}
return this[isSplice ? 'thru' : 'tap'](function(value) {
var result = func.apply(value, args);
if (value.length === 0) {
delete value[0];
}
return result;
return process(value, args);
});
};
});

View File

@@ -11823,7 +11823,7 @@
if (!isNpm) {
var wrapped = _({ '0': 1, 'length': 1 });
if (methodName == 'splice') {
wrapped.splice(0, 1);
wrapped.splice(0, 1).value();
} else {
wrapped[methodName]();
}