Skip to content

Instantly share code, notes, and snippets.

@lopugit
Created December 10, 2019 11:55
Show Gist options
  • Save lopugit/f12975b683db597cc4f6e4c04c0bd5f1 to your computer and use it in GitHub Desktop.
Save lopugit/f12975b683db597cc4f6e4c04c0bd5f1 to your computer and use it in GitHub Desktop.
Determining function types
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