0

I'd like to know if it's possible to get the name of the function which has this function in its parameters.

A practical example:

function foo () {
    console.log(somethingHere) --> 'bar'
    return true;
}

function bar (param1, param2) {}

bar(foo(), 'something');
CherryNerd
  • 1,258
  • 1
  • 16
  • 38
  • 1
    Why do you need it ? Do pass it as string as another argument... – Rayon Jul 15 '16 at 18:02
  • 1
    Your question is not very clear. besides the call to `bar(foo(), 'something')` actually has a first parameter of `true` – kennasoft Jul 15 '16 at 18:03
  • @showdev Not quite. `foo` isn't called by `bar`, `foo` returns a parameter for `bar` – 4castle Jul 15 '16 at 18:04
  • Right, bar will in the end work with `true`, but I'm creating a module for this and I'd like to find out who called `foo`, even if it's in the parameters of another function. @showdev: I have tried what was in the answer of that question, since I also found that, but it didn't work for me. – CherryNerd Jul 15 '16 at 18:05
  • 1
    Ah, I see. I also see that [arguments.callee.caller property may now be deprecated](http://stackoverflow.com/questions/103598/why-was-the-arguments-callee-caller-property-deprecated-in-javascript) anyway :-/ – showdev Jul 15 '16 at 18:05
  • 1
    `bar` didn't call `foo`. `foo` has no way of knowing how its output is used. – 4castle Jul 15 '16 at 18:07

1 Answers1

0

Function.name would return the name of the function, however in your example, bar cannot know the actual name of foo because bar only receiving the return value of foo function not foo function itself

MarkoCen
  • 2,189
  • 13
  • 24