From b5dce2f74ba1f9e7db921f954035e69a31cce0cc Mon Sep 17 00:00:00 2001 From: jdalton Date: Sun, 8 Mar 2015 01:00:04 -0800 Subject: [PATCH] Optimize `createBindWrapper`, `createPartialWrapper`, and `createHybridWrapper`. --- lodash.src.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 2b93561c5..98b3180d7 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -3213,7 +3213,8 @@ var Ctor = createCtorWrapper(func); function wrapper() { - return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments); + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + return fn.apply(thisArg, arguments); } return wrapper; } @@ -3416,7 +3417,8 @@ if (isAry && ary < args.length) { args.length = ary; } - return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : func).apply(thisBinding, args); + var fn = (this && this !== root && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func; + return fn.apply(thisBinding, args); } return wrapper; } @@ -3475,7 +3477,8 @@ while (argsLength--) { args[leftIndex++] = arguments[++argsIndex]; } - return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args); + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + return fn.apply(isBind ? thisArg : this, args); } return wrapper; }