3 ms·
the counter's value isn't leaking out, you're explicitly returning it. that's the point – the only thing you can "get out of" a closure is what it returns when
by uryga 6y ago
the counter's value isn't leaking out, you're explicitly returning it. that's the point – the only thing you can "get out of" a closure is what it returns when you call it
(see also: the JS pattern of using closures to create objects with truly private "fields")
- NegativeLatency 6y agoYou could mutate some shared/global state from inside a closure as a way of getting information/state out
- obedm 6y ago(author here) this is true! That's what I'm trying to explain in the `state` section of the article. State lives in a "global" and the component is modifying it. So it's "leaking info out". It's hard to make comprehensive mental models that cover all the bases and leaves nothing out
- uryga 6y agoi considered adding "mutate a global" in there but didn't feel like that was relevant to @iooi's comment. maybe i should've quantified "the only thing" a bit more :)