Sorry for the really weird title, but here’s what I’m trying to do:
var f1 = function (param1, param2) { // Is there a way to get an object that is ‘f1’ // (the current function)? };
As you can see, I would like to access the current function from within an anonymous function.
Is this possible?
1.1 A regular functionIt is possible to use a function expression and assign it to a regular variable, e.g. const factorial = function(n) {...} .
You call the function by typing its name and putting a value in parentheses. This value is sent to the function's parameter. e.g. We call the function firstFunction(“string as it's shown.”);
In JavaScript, an anonymous function is that type of function that has no name or we can say which is without any name. When we create an anonymous function, it is declared without any identifier. It is the difference between a normal function and an anonymous function.
Name it.
var f1 = function fOne() { console.log(fOne); //fOne is reference to this function } console.log(fOne); //undefined - this is good, fOne does not pollute global context
Yes – arguments.callee
is the current function.
NOTE: This is deprecated in ECMAScript 5, and may cause a performance hit for tail-call recursion and the like. However, it does work in most major browsers.
In your case, f1
will also work.
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