mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Updated the check of isFunction method (#4555)
This commit is contained in:
committed by
John-David Dalton
parent
a6b960be00
commit
cefddab1ca
@@ -1,5 +1,3 @@
|
|||||||
import getTag from './.internal/getTag.js'
|
|
||||||
import isObject from './isObject.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `Function` object.
|
* 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`.
|
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* isFunction(_)
|
* isFunction(class Any{})
|
||||||
* // => true
|
* // => true
|
||||||
*
|
*
|
||||||
|
* isFunction(() => {})
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* isFunction(async () => {})
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* isFunction(function * Any() {})
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* isFunction(Math.round)
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
* isFunction(/abc/)
|
* isFunction(/abc/)
|
||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isFunction(value) {
|
function isFunction(value) {
|
||||||
if (!isObject(value)) {
|
return typeof value === 'function'
|
||||||
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]'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isFunction
|
export default isFunction
|
||||||
|
|||||||
Reference in New Issue
Block a user