Although you probably shouldn't use this, you can do it for IE, Firefox, Chrome, Safari, and Opera (I admit that arguments.callee
convenient, despite the fact that it expresses certain reservations, like arguments.callee.name
, if Function.name were standard):
function getFuncName (fn) { var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn); return name ? name[1] : '(Anonymous)'; }
source share