Skip to content

Updated the checks of isFunction method #4555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions isFunction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import getTag from './.internal/getTag.js'
import isObject from './isObject.js'

/**
* Checks if `value` is classified as a `Function` object.
Expand All @@ -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