Quantcast
Viewing all articles
Browse latest Browse all 3

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:

Image may be NSFW.
Clik here to view.

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:

Image may be NSFW.
Clik here to view.

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:

Image may be NSFW.
Clik here to view.

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
  4. Writing a jQuery plugin – (part 2). Sample plugin.

Viewing all articles
Browse latest Browse all 3

Trending Articles