Updated the check of isFunction method (#4555)

This commit is contained in:
RajuPedda
2019-11-20 03:05:48 +05:30
committed by John-David Dalton
parent a6b960be00
commit cefddab1ca

View File

@@ -1,5 +1,3 @@
import getTag from './.internal/getTag.js'
import isObject from './isObject.js'
/**
* Checks if `value` is classified as a `Function` object.
@@ -10,21 +8,26 @@ import isObject from './isObject.js'
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
* @example
*
* isFunction(_)
* isFunction(class Any{})
* // => true
*
* isFunction(() => {})
* // => true
*
* isFunction(async () => {})
* // => true
*
* isFunction(function * Any() {})
* // => true
*
* isFunction(Math.round)
* // => 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 = getTag(value)
return tag == '[object Function]' || tag == '[object AsyncFunction]' ||
tag == '[object GeneratorFunction]' || tag == '[object Proxy]'
return typeof value === 'function'
}
export default isFunction