DEV Community

Discussion on: Is there a suitable equivalent to `Function.caller` in modern JS?

Collapse
akashkava profile image
Akash Kava

Not possible but you can use symbols to store private data and expose those symbols to friend functions.

Collapse
georgecoldham profile image
George

A sadly irritating workaround :/

Collapse
baenencalin profile image
Calin Baenen Author

I know. - Also dangerous because it's not completely private.

Collapse
baenencalin profile image
Calin Baenen Author

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 Proxys.