in reply to Closures Explained
“Padewan, when you need to use Closures, you will know.”
In a word, “a closure has a memory.” That is, it has access to a set of variables and values, that are known only to itself but that are persistent (and unique) for as long as the closure itself exists.
So, for example, I could hand you a closure that, each time you call upon it, returns a number one-greater than the number it returned the last time you called upon it. And yet, I could hand you just as many copies of that closure as I desired, and each one would exhibit that behavior.
“Cool, huh?”
Replies are listed 'Best First'. | |
---|---|
Re^2: Closures Explained
by Jenda (Abbot) on Jul 14, 2009 at 15:21 UTC |