Function.caller
JavaScript 1.1+, JScript 1.0+ Nav3+, NES2+, IE 3+, Opera3+ Syntax
function.caller
Description:
The caller property of the Function object is used to reference the function that called the currently executing function.
Example
Listing 6.129 shows how the caller property is used to get the name of the function calling John().
Listing 6.129 Accessing the caller Property
<html> <body> <script lanuguage="JavaScript1.1"> <!–– Hide // Define a simple function Alice(), which calls the John() function. function Alice(){ var Boss = true; John(); } // function outputs its caller function John(){ myBoss = John.caller.name; document.write("The boss is: " + myBoss + "<br>"); } // End Hide ––> </script> </body> </html> |
Get Pure JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.