mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Bump to v3.0.0.
This commit is contained in:
38
internal/isBindable.js
Normal file
38
internal/isBindable.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import baseSetData from './baseSetData';
|
||||
import isNative from '../lang/isNative';
|
||||
import support from '../support';
|
||||
|
||||
/** Used to detect named functions. */
|
||||
var reFuncName = /^\s*function[ \n\r\t]+\w/;
|
||||
|
||||
/** Used to detect functions containing a `this` reference. */
|
||||
var reThis = /\bthis\b/;
|
||||
|
||||
/** Used to resolve the decompiled source of functions. */
|
||||
var fnToString = Function.prototype.toString;
|
||||
|
||||
/**
|
||||
* Checks if `func` is eligible for `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to check.
|
||||
* @returns {boolean} Returns `true` if `func` is eligible, else `false`.
|
||||
*/
|
||||
function isBindable(func) {
|
||||
var result = !(support.funcNames ? func.name : support.funcDecomp);
|
||||
|
||||
if (!result) {
|
||||
var source = fnToString.call(func);
|
||||
if (!support.funcNames) {
|
||||
result = !reFuncName.test(source);
|
||||
}
|
||||
if (!result) {
|
||||
// Check if `func` references the `this` keyword and store the result.
|
||||
result = reThis.test(source) || isNative(func);
|
||||
baseSetData(func, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default isBindable;
|
||||
Reference in New Issue
Block a user