mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Cleanup string methods added to LodashWrapper.
This commit is contained in:
@@ -854,12 +854,14 @@
|
|||||||
* Chaining is supported in custom builds as long as the `_#value` method is
|
* Chaining is supported in custom builds as long as the `_#value` method is
|
||||||
* directly or indirectly included in the build.
|
* directly or indirectly included in the build.
|
||||||
*
|
*
|
||||||
* In addition to lodash methods, wrappers also have the following `Array` methods:
|
* In addition to lodash methods, wrappers have `Array` and `String` methods.
|
||||||
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
|
|
||||||
* and `unshift`
|
|
||||||
*
|
*
|
||||||
* These `String` methods are also available:
|
* The wrapper `Array` methods are:
|
||||||
* `split` and `replace`
|
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
|
||||||
|
* `splice`, and `unshift`
|
||||||
|
*
|
||||||
|
* The wrapper `String` methods are:
|
||||||
|
* `replace` and `split`
|
||||||
*
|
*
|
||||||
* The wrapper methods that support shortcut fusion are:
|
* The wrapper methods that support shortcut fusion are:
|
||||||
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
|
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
|
||||||
@@ -11710,29 +11712,22 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add `Array.prototype` and `String.prototype` functions to `lodash.prototype`.
|
// Add `Array` and `String` methods to `lodash.prototype`.
|
||||||
arrayEach(['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift',
|
arrayEach(['concat', 'join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
|
||||||
'split', 'replace'], function(methodName) {
|
var protoFunc = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
|
||||||
var arrayFunc = arrayProto[methodName],
|
|
||||||
stringFunc = stringProto[methodName],
|
|
||||||
isStringFunc = /^(?:split|replace)$/.test(methodName),
|
|
||||||
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
||||||
fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName),
|
fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName),
|
||||||
retUnwrapped = /^(?:join|pop|shift)$/.test(methodName);
|
retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
|
||||||
|
|
||||||
if (isStringFunc) {
|
// Avoid array-like object bugs with `Array#shift` and `Array#splice` in
|
||||||
var func = stringFunc;
|
// IE < 9, Firefox < 10, Narwhal, and RingoJS.
|
||||||
} else {
|
var func = !fixObjects ? protoFunc : function() {
|
||||||
// Avoid array-like object bugs with `Array#shift` and `Array#splice` in
|
var result = protoFunc.apply(this, arguments);
|
||||||
// IE < 9, Firefox < 10, Narwhal, and RingoJS.
|
if (this.length === 0) {
|
||||||
var func = !fixObjects ? arrayFunc : function() {
|
delete this[0];
|
||||||
var result = arrayFunc.apply(this, arguments);
|
}
|
||||||
if (this.length === 0) {
|
return result;
|
||||||
delete this[0];
|
};
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
|
|||||||
Reference in New Issue
Block a user