Add _#toString and _#valueOf.

Former-commit-id: adb194b6270fc72f794c69343891a2e891b90051
This commit is contained in:
John-David Dalton
2012-11-18 21:50:41 -08:00
parent 20630aeb47
commit 819d4abaa2
4 changed files with 48 additions and 1 deletions

View File

@@ -4043,6 +4043,22 @@
return this;
}
/**
* Produces the `toString` result of the wrapped value.
*
* @name toString
* @memberOf _
* @category Chaining
* @returns {String} Returns the string result.
* @example
*
* _([1, 2, 3]).toString();
* // => '1,2,3'
*/
function wrapperToString() {
return String(this.__wrapped__);
}
/**
* Extracts the wrapped value.
*
@@ -4196,7 +4212,9 @@
// add `lodash.prototype.chain` after calling `mixin()` to avoid overwriting
// it with the wrapped `lodash.chain`
lodash.prototype.chain = wrapperChain;
lodash.prototype.toString = wrapperToString;
lodash.prototype.value = wrapperValue;
lodash.prototype.valueOf = wrapperValue;
// add all mutator Array functions to the wrapper.
forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {