I need the current function name as a string to log to our log facility. But arguments.callee.name only works in loose mode. How to get the function name under "use strict"?
arguments.callee.name
"use strict"
For logging/debugging purposes, you can create a new Error object in the logger and inspect its .stack property, e.g.
Error
.stack
function logIt(message) { var stack = new Error().stack, caller = stack.split(' ')[2].trim(); console.log(caller + ":" + message); } function a(b) { b() } a(function xyz() { logIt('hello'); });
1.4m articles
1.4m replys
5 comments
57.0k users