开发者

What would you call "callback" or "closure" in general?

开发者 https://www.devze.com 2022-12-21 03:28 出处:网络
Which keyword / tag should we use to describe them when we\'re taking notes for them. If they are placed under the category \"software design\", is it appropriate?

Which keyword / tag should we use to describe them when we're taking notes for them.

If they are placed under the category "software design", is it appropriate?

@edit: It's more ab开发者_StackOverflow社区out how you category things. When you are in learning, some terminology appears, so what category will you assign it in your own ontology?


Right, I suspect I’m going to reveal my stupidity here, but anyway:

  • “callback”: a function (A) passed to another function (B), that’ll be called in B to do work.
  • “closure”: a function that captures the value of variables from the scope in which it was defined

Hopefully defining them will help you classify them — I don’t think the terms “callback” and “closure” actually mean the same thing, although they can both refer to the same thing depending on context.

I’ve made this answer community wiki, so please feel free to edit it until it’s correct.

callback

  • http://en.wikipedia.org/wiki/Callback_(computer_science)

    a callback is executable code that is passed as an argument to other code

  • “What is a callback function?” (Stack Overflow)

closure

  • http://en.wikipedia.org/wiki/Closure_(computer_science)

    The term closure is often mistakenly used to mean anonymous function. This is probably because most languages implementing anonymous functions allow them to form closures and programmers are usually introduced to both concepts at the same time. These are, however, distinct concepts


I think Function Pointer can be used as tag for "callback" or "closures".


I consider "Closures" and "Callbacks" related but nowhere equivalent. The lowest common denominator between the two I would say are "Higher-Order Functions", which take place in "Functional Programming".

http://en.wikipedia.org/wiki/Higher_order_functions

http://en.wikipedia.org/wiki/Functional_programming

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号