The function. caller property of the JavaScript function object returns the function that invoked the specified function. It returns null if the function “f” was invoked by the top-level code in JavaScript. For functions like strict functions, async functions and generator function this method returns null.
You can do that by compiling with the --noImplicitUseStrict compiler option—add "noImplicitUseStrict": true to "compilerOptions" in tsconfig. json. Doing so will prevent the compiler from emitting "use strict" .
You can use Function. Caller to get the calling function.
Strict and non-strict code can be mixed. But you can't use caller even if the call to it is not in strict code. Does anybody know any workaround?
I tried this:
(function strict(){ "use strict"; nonStrict();//ok nonStrictCaller();//error :( })(); function nonStrict(){ return 011;//Octal literals are not allowed in strict mode } function nonStrictCaller(){ return nonStrictCaller.caller; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With