Created
December 1, 2013 06:41
-
-
Save FLasH3r/7729292 to your computer and use it in GitHub Desktop.
function-name - Get the name of a named function
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
/*! | |
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