Sorry for the really weird title, but here’s what I’m trying to do:
JavaScript
x
7
1
var f1 = function (param1, param2) {
2
3
// Is there a way to get an object that is ‘f1’
4
// (the current function)?
5
6
};
7
As you can see, I would like to access the current function from within an anonymous function.
Is this possible?
Advertisement
Answer
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.