How do you find out the caller function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 29-Jan-2018 10:01:02
Advertisements