mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Avoid binding functions in _.createCallback if they don't reference this.
Former-commit-id: d491414e7e1536d3241a607ba07120f629ff2410
This commit is contained in:
42
lodash.js
42
lodash.js
@@ -55,6 +55,9 @@
|
||||
/** Used to match "interpolate" template delimiters */
|
||||
var reInterpolate = /<%=([\s\S]+?)%>/g;
|
||||
|
||||
/** Used to detect functions containing a `this` reference */
|
||||
var reThis = (reThis = /\bthis\b/) && reThis.test(runInContext) && reThis;
|
||||
|
||||
/** Used to detect and test whitespace */
|
||||
var whitespace = (
|
||||
// whitespace
|
||||
@@ -188,6 +191,7 @@
|
||||
clearTimeout = context.clearTimeout,
|
||||
concat = arrayProto.concat,
|
||||
floor = Math.floor,
|
||||
fnToString = Function.prototype.toString,
|
||||
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||
hasOwnProperty = objectProto.hasOwnProperty,
|
||||
push = arrayProto.push,
|
||||
@@ -4578,27 +4582,27 @@
|
||||
return result;
|
||||
};
|
||||
}
|
||||
if (typeof thisArg != 'undefined') {
|
||||
if (argCount === 1) {
|
||||
return function(value) {
|
||||
return func.call(thisArg, value);
|
||||
};
|
||||
}
|
||||
if (argCount === 2) {
|
||||
return function(a, b) {
|
||||
return func.call(thisArg, a, b);
|
||||
};
|
||||
}
|
||||
if (argCount === 4) {
|
||||
return function(accumulator, value, index, collection) {
|
||||
return func.call(thisArg, accumulator, value, index, collection);
|
||||
};
|
||||
}
|
||||
return function(value, index, collection) {
|
||||
return func.call(thisArg, value, index, collection);
|
||||
if (typeof thisArg == 'undefined' || (reThis && !reThis.test(fnToString.call(func)))) {
|
||||
return func;
|
||||
}
|
||||
if (argCount === 1) {
|
||||
return function(value) {
|
||||
return func.call(thisArg, value);
|
||||
};
|
||||
}
|
||||
return func;
|
||||
if (argCount === 2) {
|
||||
return function(a, b) {
|
||||
return func.call(thisArg, a, b);
|
||||
};
|
||||
}
|
||||
if (argCount === 4) {
|
||||
return function(accumulator, value, index, collection) {
|
||||
return func.call(thisArg, accumulator, value, index, collection);
|
||||
};
|
||||
}
|
||||
return function(value, index, collection) {
|
||||
return func.call(thisArg, value, index, collection);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user