From 2026cbeebd0a0e1f60b68b0951c3205c99e59101 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 24 Sep 2016 09:40:43 -0700 Subject: [PATCH] Add `thrower` helper. --- lodash.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index c27638b24..391973540 100644 --- a/lodash.js +++ b/lodash.js @@ -1333,6 +1333,19 @@ : asciiToArray(string); } + /** + * Creates a function that throws an error with `message`. + * + * @private + * @param {stirng} message The error message. + * @returns {Function} Returns the new thrower function. + */ + function thrower(message) { + return function() { + throw new Error(message); + }; + } + /** * Used by `_.unescape` to convert HTML entities to characters. * @@ -1488,13 +1501,14 @@ var nativeCeil = Math.ceil, nativeFloor = Math.floor, nativeGetSymbols = Object.getOwnPropertySymbols, + nativeIsArray = Array.isArray || (Array.isArray = thrower(SHIM_ERROR_TEXT)), nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object.keys, Object), nativeMax = Math.max, nativeMin = Math.min, - nativeNow = Date.now, + nativeNow = Date.now || (Date.now = thrower(SHIM_ERROR_TEXT)), nativeParseInt = context.parseInt, nativeRandom = Math.random, nativeReverse = arrayProto.reverse; @@ -11162,9 +11176,7 @@ * _.isArray(_.noop); * // => false */ - var isArray = Array.isArray || (Array.isArray = function() { - throw new Error(SHIM_ERROR_TEXT); - }); + var isArray = nativeIsArray; /** * Checks if `value` is classified as an `ArrayBuffer` object.