0

Possible Duplicate:
Determine calling function in javascript

Suppose I have a function in javascript, and I want to know who is the caller. Is this possible without using a global variables/parameters approach?

0

1 Answer 1

0

To be compatible with a wide selection of browsers, you need something like:

if (typeof arguments.caller == 'function') { return arguments.caller; } else if (typeof arguments.callee == 'function' && typeof arguments.callee.caller == 'function') { return arguments.callee.caller; } else { // called from global scope, in strict mode or browser doesn't support // either of the above access methods } 

Note that accessing arguments.callee or caller will throw an exception in ES5 strict mode, the above may avoid that but I can't test it right now.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.