Files
lodash/isFunction.js
2017-01-10 01:09:46 -08:00

36 lines
980 B
JavaScript

import baseGetTag from './.internal/baseGetTag.js';
import isObject from './isObject.js';
/** `Object#toString` result references. */
const asyncTag = '[object AsyncFunction]';
const funcTag = '[object Function]';
const genTag = '[object GeneratorFunction]';
const proxyTag = '[object Proxy]';
/**
* Checks if `value` is classified as a `Function` object.
*
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
* @example
*
* isFunction(_);
* // => true
*
* isFunction(/abc/);
* // => false
*/
function isFunction(value) {
if (!isObject(value)) {
return false;
}
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 9 which returns 'object' for typed arrays and other constructors.
const tag = baseGetTag(value);
return tag == funcTag || tag == asyncTag || tag == genTag || tag == proxyTag;
}
export default isFunction;