0

I have a JavaScript function that needs to behave differently if is called from another function. I have no control of the invocation of my function, so I can't do that based on parameter passing.

So, I was planning on identifying which function is doing the call, and behaving differently if that call comes from this specific function. To do that, I found these approaches:

  • Get the reference through arguments.caller, but I found it is a soon-to-be deprecated attribute.
  • Get the reference through Function.caller, but it is not a standard.

So every approach I found seems to have a pitfall. Which is the recommended approach for that? By the way, I'm using ExtJS Framework, maybe there's an specific way for doing that there.

Carlos Gavidia-Calderon
  • 7,145
  • 9
  • 34
  • 59
  • 5
    I don't know that there's any "recommended" approach, since the need to do this would generally be thought of as a design flaw. It would help if you could explain more about the situation. – Pointy Sep 22 '14 at 16:26
  • 1
    I would go further and say there is no recommended approach to identifying the caller and solving your problem that way. The recommended approach is to fix the design so that you can solve your issue with well supported, standards-based code that uses good design patterns. This will probably involve rethinking the overall problem from a much higher level rather than trying to hack a solution in at a low level. – jfriend00 Sep 22 '14 at 16:31

1 Answers1

0

You can also intercept the function call and add an extra parameter... mroe detail here : http://www.vinylfox.com/patterns-using-ext-js-sequence-and-intercept/

There is a solution for your implmeentation here: https://stackoverflow.com/a/22165274/1386469

Community
  • 1
  • 1
Dawesi
  • 568
  • 3
  • 9