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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.