1

I'd like a general console.log snippet I can add to all functions without having to type out the function name each time.

function unknownName() {
 //psuedo code
 console.log(`this function's name: ${_thisFunction_.name}`); 
}

Restrictions:

  1. arguments.callee.name doesn't work in strict mode.
  2. I don't want to bind every function to be able to use 'this'
  3. I don't know the function name in advance. Ex (from mozilla.org):

function doSomething() {}
doSomething.name; // "doSomething"
ibrahim mahrir
  • 31,174
  • 5
  • 48
  • 73
Ron I
  • 4,090
  • 8
  • 33
  • 64
  • Are you just curious to know whether it’s possible or are you trying to solve a real problem where you need to know the function’s name? – Sebastian Simon Dec 04 '17 at 21:50
  • Not generally possible. see last paragraph of [mdn on `arguments.callee`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee#A_use_of_arguments.callee_with_no_good_alternative) – trincot Dec 04 '17 at 22:01
  • @Xufox - I am trying to work out a general code snippet to add to all functions that could tie to a log manager, so a real problem. – Ron I Dec 04 '17 at 22:54

0 Answers0