diff --git a/build.js b/build.js index 8868f69c7..d3c571375 100644 --- a/build.js +++ b/build.js @@ -1634,9 +1634,8 @@ // remove `__bindData__` logic and `setBindData` function calls from `_.createCallback` source = source.replace(matchFunction(source, 'createCallback'), function(match) { return match - .replace(/^( *)var bindData *=[\s\S]+?\n\1}\n/m, '') - .replace(/\s*\|\|\s*!bindData\b/, '') - .replace(/^( *)else if \(bindData[\s\S]+?\n\1}\n/m, '') + .replace(/(?:\s*\/\/.*)\n( *)var bindData *=[\s\S]+?\n\1}/, '') + .replace(/(?:\s*\/\/.*)\n( *)if *\(bindData[\s\S]+?\n\1}/, ''); }); return source; @@ -2729,7 +2728,7 @@ } if (isLegacy || isMobile || isUnderscore) { _.each(['createBound', 'createCallback'], function(funcName) { - funcDependencyMap[funcName] = _.without(funcDependencyMap[funcName], 'bind', 'setBindData'); + funcDependencyMap[funcName] = _.without(funcDependencyMap[funcName], 'setBindData'); }); } if (_.contains(plusFuncs, 'chain') == !isUnderscore) { diff --git a/lodash.js b/lodash.js index dcd2563ae..b6005c344 100644 --- a/lodash.js +++ b/lodash.js @@ -4848,20 +4848,20 @@ return result; }; } - var bindData = func.__bindData__; + // exit early if there is no `thisArg` + if (typeof thisArg == 'undefined') { + return func; + } + var bindData = !func.name || func.__bindData__; if (typeof bindData == 'undefined') { // checks if `func` references the `this` keyword and stores the result bindData = !reThis || reThis.test(fnToString.call(func)); setBindData(func, bindData); } - if (typeof thisArg == 'undefined' || !bindData) { + // exit early if there are no `this` references or `func` is bound + if (bindData !== true && !(bindData && bindData[4])) { return func; } - else if (bindData !== true) { - // exit early if already bound or leverage bind optimizations if - // created by `_.partial` or `_.partialRight` - return bindData[4] ? bind(func, thisArg) : func; - } switch (argCount) { case 1: return function(value) { return func.call(thisArg, value); @@ -4876,9 +4876,7 @@ return func.call(thisArg, accumulator, value, index, collection); }; } - return function() { - return func.apply(thisArg, arguments); - }; + return bind(func, thisArg); } /**