Skip to content

Instantly share code, notes, and snippets.

@FLasH3r
Created December 1, 2013 06:41
Show Gist options
  • 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