Created
December 10, 2019 11:55
-
-
Save lopugit/f12975b683db597cc4f6e4c04c0bd5f1 to your computer and use it in GitHub Desktop.
Determining function types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flags = { | |
function: f instanceof Function, | |
name: undefined, | |
native: false, | |
bound: false, | |
plain: false, | |
arrow: false | |
}; | |
if (flags.function) { | |
flags.name = f.name || '(anonymous)'; | |
flags.native = f.toString().trim().endsWith('() { [native code] }'); | |
flags.bound = flags.native && flags.name.startsWith('bound '); | |
flags.plain = !flags.native && f.hasOwnProperty('prototype'); | |
flags.arrow = !(flags.native || flags.plain); | |
} | |
return flags; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment