How is a closure different from a callback?

Check the introduction in this: http://jibbering.com/faq/faq_notes/closures.html. It can help you understand better how closures relate to functions.

Here is a set of closure examples: http://www.javascriptkit.com/javatutors/closures2.shtml

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