What is a callback function?

前端 未结 21 2501
耶瑟儿~
耶瑟儿~ 2020-11-21 23:01

What is a callback function?

21条回答
  •  梦如初夏
    2020-11-21 23:38

    A callback function is a function you pass (as a reference or a pointer) to a certain function or object. This function or object will call this function back any time later, possibly multiple times, for any kind of purpose :

    • notifying the end of a task
    • requesting comparison between two item (like in c qsort())
    • reporting progress of a process
    • notifying events
    • delegating the instanciation of an object
    • delegating the painting of an area

    ...

    So describing a callback as a function being called at the end of another function or task is overly simplifying (even if it's a common use case).

提交回复
热议问题