mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 20:37:48 +00:00
More cleanup of chaining code.
This commit is contained in:
20
lodash.js
20
lodash.js
@@ -9599,8 +9599,9 @@
|
|||||||
if (!this.__chain__ && (n == null || guard)) {
|
if (!this.__chain__ && (n == null || guard)) {
|
||||||
return lodash.sample(this.value());
|
return lodash.sample(this.value());
|
||||||
}
|
}
|
||||||
this.__queue__.push(['sample', lodash, [n]]);
|
return this.tap(function(value) {
|
||||||
return this;
|
lodash.sample(value);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
@@ -9636,7 +9637,7 @@
|
|||||||
return func.apply(this.value(), args);
|
return func.apply(this.value(), args);
|
||||||
}
|
}
|
||||||
return this.tap(function(value) {
|
return this.tap(function(value) {
|
||||||
return func.apply(value, args);
|
func.apply(value, args);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -9661,23 +9662,20 @@
|
|||||||
var func = arrayProto[methodName],
|
var func = arrayProto[methodName],
|
||||||
isSplice = methodName == 'splice';
|
isSplice = methodName == 'splice';
|
||||||
|
|
||||||
function process(value, args) {
|
function wrapper(value, args) {
|
||||||
var result = func.apply(value, args);
|
var result = func.apply(value, args);
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
delete value[0];
|
delete value[0];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = arguments,
|
var args = arguments;
|
||||||
chainAll = this.__chain__;
|
if (!this.__chain__ && !isSplice) {
|
||||||
|
return wrapper(this.value(), args);
|
||||||
if (!chainAll && !isSplice) {
|
|
||||||
return process(this.value(), args);
|
|
||||||
}
|
}
|
||||||
return this[isSplice ? 'thru' : 'tap'](function(value) {
|
return this[isSplice ? 'thru' : 'tap'](function(value) {
|
||||||
return process(value, args);
|
return wrapper(value, args);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user