Skip to main content
added 8 characters in body
Source Link
rolfv1
  • 571
  • 1
  • 3
  • 14

As already mentioned in the comments, the way you present it, this is not possible, it only works if the function foo is called from a function, which then of course has to be a different function for each script, then you can use

console.log(arguments.callee.caller.name)

That will give you the name of the function that called your function foo.

Edit: and really, if it's important to know from where the script was called, just use an argument, like function foo(caller){, which indicates how the function was called, that's much safer than relying on the arguments.callee.caller thing.

As already mentioned in the comments, the way you present it, this is not possible, it only works if the function foo is called from a function, which then of course has to be a different function for each script, then you can use

console.log(arguments.callee.caller.name)

That will give you the name of the function that called your function foo.

Edit: and really, if it's important to know from where the script was called, just use an argument function foo(caller) which indicates how the function was called, that's much safer than relying on the arguments.callee.caller thing.

As already mentioned in the comments, the way you present it, this is not possible, it only works if the function foo is called from a function, which then of course has to be a different function for each script, then you can use

console.log(arguments.callee.caller.name)

That will give you the name of the function that called your function foo.

Edit: and really, if it's important to know from where the script was called, just use an argument, like function foo(caller){, which indicates how the function was called, that's much safer than relying on the arguments.callee.caller thing.

Source Link
rolfv1
  • 571
  • 1
  • 3
  • 14

As already mentioned in the comments, the way you present it, this is not possible, it only works if the function foo is called from a function, which then of course has to be a different function for each script, then you can use

console.log(arguments.callee.caller.name)

That will give you the name of the function that called your function foo.

Edit: and really, if it's important to know from where the script was called, just use an argument function foo(caller) which indicates how the function was called, that's much safer than relying on the arguments.callee.caller thing.