Skip to content

Instantly share code, notes, and snippets.

@FLasH3r
Created December 1, 2013 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FLasH3r/7729292 to your computer and use it in GitHub Desktop.
Save FLasH3r/7729292 to your computer and use it in GitHub Desktop.
function-name - Get the name of a named function
/*!
function-name
Get the name of a named function
https://github.com/sindresorhus/function-name
by Sindre Sorhus
MIT License
*/
function functionName(fn) {
if (typeof fn !== 'function') {
throw new TypeError('Expected a function.');
}
return fn.name || (/function ([^\(]+)/.exec(fn.toString()) || [])[1] || null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment