4 ms·
An object has state, so imagine you have a skeleton and every time you change a property you are taking off an old bone and putting on a new bone. Eventually y
by sova 11y ago
An object has state, so imagine you have a skeleton and every time you change a property you are taking off an old bone and putting on a new bone. Eventually you might have 3 femurs, a couple of skulls, and five knees because of how objects are implemented (and how hard it is to keep straight).
A closure is like if you needed a forearm, you created one on-the-fly for the specific instance, and it exists as long as it's needed. You would never have the issue of having excess multiples of arms or legs because closures, although maintaining an internal state, only exist as long as they are invoked.
It's a simple example, but maybe that helps clear it up. Perhaps some people can help extend the metaphor if it proves useful.