Avoid binding functions in _.createCallback if they don't reference this.

Former-commit-id: d491414e7e1536d3241a607ba07120f629ff2410
This commit is contained in:
John-David Dalton
2013-05-20 09:20:51 -07:00
parent 242e8a3bd6
commit 01621f75b6
3 changed files with 116 additions and 35 deletions

View File

@@ -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);
};
}
/**