How is a closure different from a callback?

前端 未结 9 973
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 19:08

I asked a question about callbacks and arrived at another question (see comment). How is a closure different from a callback?

9条回答
  •  囚心锁ツ
    2020-12-07 19:57

    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.

提交回复
热议问题