How is a closure different from a callback?

Check the introduction in this: It can help you understand better how closures relate to functions.

Here is a set of closure examples:

Basically, the callback is like a function pointer. The bit that makes it a closure, is when that function accesses anything on the context where it lives, like variables outside it. When that happens, the function will use the current values of the variables (as opposed to copy them). See example 4.

Leave a Comment