Computer >> Computer tutorials >  >> Programming >> Javascript

How do you find out the caller function in JavaScript?


To find the caller function, you need to use the non-standard feature “function.caller”. Previously, “argument.caller” property was considered, which is now obsolete.

Example

You can try to run the following function to get the caller function

Live Demo

<html>
   <head>
      <script type="text/javascript">
         function Display() {
            alert("caller is " + Display.caller);
         }
      </script>
   </head>
   <body>
      <p>Click the following button:</p>
      <form>
         <input type = "button" onclick = "Display()" value="Get caller function">
      </form>
   </body>
</html>