javascript: get function caller

Who calls me?

If that’s the question a JavaScript function is asking for, and respectively you are, there is one simple way to find the answer.

Why would I need this?

Well let assume I’ve one function called func1, called by both func2 and func3, explained into the following example:

How I’d finally understand the answer?

Well if you’re using Firefox, I guess you are if web developing is your job, just add a console.log to see the caller function. Like in the above example. The answer can be seen in the Firebug console:

That is fine enough to understand the caller function and if needed to debug the js application. You need only to make for the test a simple HTML file. Example:

Download

You can download the example from here, or visit the download page.

Related posts:

  1. write in the Safari javascript console
  2. How to detect a variable existence in JavaScript?
  3. JavaScript closures in brief
This entry was posted in javascript, micro tutorial and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">