help
help copied to clipboard
Function Caller Top-Level ?
Details
I want to recover the caller function but if the function is not clearly defined in my script I can't get it it's empty
Node.js version
18.5.0
Example code
function Hello()
{
console.log(Hello.caller.toString()); //"log" should bere here, same if I use "eval" I suppose
}
console.log(Hello())
Operating system
Windows 10
Scope
Code/Runtime
Module and version
No response
console.log is not calling your function, so it would be incorrect for it to be there. at the top level, the script itself is the caller and it is not a function so there's nothing that can be put there. additionally function.caller is deprecated and not available in strict mode so I'd highly recommend not using it at all.
console.logis not calling your function, so it would be incorrect for it to be there. at the top level, the script itself is the caller and it is not a function so there's nothing that can be put there. additionally function.caller is deprecated and not available in strict mode so I'd highly recommend not using it at all. Oh yeah true but I was thinking it was probably just a bug, then what would be your advice to detect if I used console.log or eval on top of Hello for example ?
Oh yeah true but I was thinking it was probably just a bug, then what would be your advice to detect if I used console.log or eval on top of Hello for example
@devsnek just seen you are a Discord staff in Discord API server, I don't know for which part you work for at Discord but I bet it's in the engineerie, don't blame me if I'm wrong I can't really guess lol.
So is there any way to know if Before/After a function it's eval or console.log or anything else that have been used ?