mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 04:17:49 +00:00
Add hasThis to avoid repeatedly checking for this.
Former-commit-id: 15ce8566364ddac60ac01f3a36343c33d9739b77
This commit is contained in:
30
lodash.js
30
lodash.js
@@ -1204,6 +1204,34 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `func` references the `this` keyword.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to inspect.
|
||||
* @returns {Boolean} Returns `true` if `this` is referenced, else `false`.
|
||||
*/
|
||||
function hasThis(func) {
|
||||
var result = func.__hasThis__;
|
||||
if (typeof result == 'boolean') {
|
||||
return result;
|
||||
}
|
||||
result = reThis.test(fnToString.call(func));
|
||||
defineProperty(func, '__hasThis__', {
|
||||
'configurable': true,
|
||||
'enumerable': false,
|
||||
'writable': true,
|
||||
'value': result
|
||||
});
|
||||
return result;
|
||||
}
|
||||
// fallback for older browsers
|
||||
if (!defineProperty || !reThis) {
|
||||
hasThis = function() {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A fallback implementation of `isPlainObject` which checks if a given `value`
|
||||
* is an object created by the `Object` constructor, assuming objects created
|
||||
@@ -4784,7 +4812,7 @@
|
||||
return result;
|
||||
};
|
||||
}
|
||||
if (typeof thisArg == 'undefined' || (reThis && !reThis.test(fnToString.call(func)))) {
|
||||
if (typeof thisArg == 'undefined' || !hasThis(func)) {
|
||||
return func;
|
||||
}
|
||||
if (argCount === 1) {
|
||||
|
||||
Reference in New Issue
Block a user