DEV Community

Discussion on: A JavaScript interview question asked at Google

Collapse
 
briancodes profile image
Brian • Edited

That's a good question, and the solution is really clearđź‘Ť

I'm not sure I'd call the emit function a closure, it's not returning a function, and it's not being run outside it's lexical scope (although the callbacks are closures themselves I guess)

Collapse
 
elisabethgross profile image
elisabethgross

Not the emit function - the event callbacks themself close over the data object and gain access to that themselves!