From 78f17bd083f15a6885beba38bc3c60b9bf6378da Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 7 Apr 2014 09:23:40 -0700 Subject: [PATCH] Add `toJSON` alias of `valueOf`. [closes #521] --- lodash.js | 3 ++- test/test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 822337bd6..456f11b57 100644 --- a/lodash.js +++ b/lodash.js @@ -3561,7 +3561,7 @@ * * @name valueOf * @memberOf _ - * @alias value + * @alias value, toJSON * @category Chaining * @returns {*} Returns the wrapped value. * @example @@ -8427,6 +8427,7 @@ // add "Chaining" functions to the wrapper lodash.prototype.chain = wrapperChain; + lodash.prototype.toJSON = wrapperValueOf; lodash.prototype.toString = wrapperToString; lodash.prototype.value = wrapperValueOf; lodash.prototype.valueOf = wrapperValueOf; diff --git a/test/test.js b/test/test.js index 5182f7fcb..2179f5a57 100644 --- a/test/test.js +++ b/test/test.js @@ -9659,6 +9659,17 @@ skipTest(); } }); + + test('should be aliased', 2, function() { + if (!isNpm) { + var expected = _.prototype.valueOf; + strictEqual(_.prototype.toJSON, expected); + strictEqual(_.prototype.value, expected); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/