get a function name from the function in Javascript

One day I needed to get the function name from the function itself. Here is what I found.

function functionName(fn)
var name=/\W*function\s+([\w\$]+)\(/.exec(fn);
if(!name)return 'No name';
return name[1];


Latest posts by Fab (see all)

About Fab

Solutions Architect, I build great workflows for the news, media and broadcast industries. I play with data too.

Leave a comment

Your email address will not be published. Required fields are marked *