1

If I have this code:

const foo = cb => {console.log(cb.name)} //access here

const bar = ()=>null

foo(()=>bar())

Is there a way for me to access bar's prototype from foo? (in this case the name)

cb.name // '' (anonymous function)
cb().name // tries to access null.name (return of bar)

This question is more about my curiosity, I'm not looking for workarounds.

cubefox
  • 1,251
  • 14
  • 29
  • 1
    no, that's the point of arrow functions. https://stackoverflow.com/questions/27977525/how-do-i-write-a-named-arrow-function-in-es2015 – Roco CTZ Apr 05 '19 at 09:45

1 Answers1

0

Well, you can get the name, kind of:

 const foo = cb => {
  console.log(cb.toString())
 };

But no, thats not useful at all, dont do that.

Is there a way for me to access bar's prototype from foo?

No, no way from within the code. Add a breakpoint with the debugger, then you can navigate there via stack > cb.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151