arguments.callee
unfortunatelly deprecated, and using it throws an error in "strict mode".
Is there any new proper(standard) alternative for getting function name inside actual function? Or will it be in future plans ECMA6, 7?
Recent answer is no more than dirty hack and not acceptable for me answer.
And arguments.callee.caller.name
not working either (nodejs v7.5.0)
A function is most often denoted by letters such as f, g and h, and the value of a function f at an element x of its domain is denoted by f(x); the numerical value resulting from the function evaluation at a particular input value is denoted by replacing x with this value; for example, the value of f at x = 4 is ...
Using Strict mode for a function: Likewise, to invoke strict mode for a function, put the exact statement “use strict”; (or 'use strict';) in the function's body before any other statements. Examples of using Strict mode: Example: In normal JavaScript, mistyping a variable name creates a new global variable.
The "use strict" Directive It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.
Is there any new proper (standard) alternative for getting function name inside actual function?
No, there is not.
Or will it be in future plans for ES?
No, given that there is no need for it. Inside the current function, you know the name and could just as well use a string literal, in other functions you just need some reference (but not .callee
).
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