So, as MDN (Mozilla Developer Network) says, Function.caller
is not only deprecated, but removed from the Relevant Web Standards.
But, this isn't good for me, as I want to know what function is calling a function I have.
I have a set of private variables, and I only want "friend functions" to see those variables without having to return every function from another function. (Also because these private variables are user-defined, and thus can't be predicted, or written in advance.)
So, I was wondering, does modern JS provide anything similar to Function.caller
?
Top comments (6)
Not possible but you can use symbols to store private data and expose those symbols to friend functions.
That's the approach I'm going for now, but it would have been nice if
Function.prototype.caller
still existed, because then I could just make a getter function for each key, and call it a day.Sadly, symbols can still be exposed, unless you want to work with
Proxy
s.A sadly irritating workaround :/
I know. - Also dangerous because it's not completely private.
Sounds a bit like an XY Problem
XY?