回调函数callback

2021-03-10  本文已影响0人  汉江岳

维基百科定义

 a callback, is any executable code that is passed as an argument to other code; that other code is expected to call back(execute) the argument at a given time. This execution may be immediate as in a synchronous callback, or it might happen at a later point in time as in an asynchronous callback.

翻译成中文:回调是指一段可执行的代码被作为参数传递到另一个代码中,并在特定的时间去执行。执行方式可以是同步,也可以是异步。


image.png

callback 一词本来用于打电话。你可以打电话(call)给别人,也可以留下电话号码,让别人回电话(callback)。
你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货。在这个例子里,你的电话号码就叫回调函数,你把电话留给店员就叫登记回调函数,店里后来有货了叫做触发了回调关联的事件,店员给你打电话叫做调用回调函数,你到店里去取货叫做响应回调事件。

参考

  1. https://www.zhihu.com/question/19801131
上一篇 下一篇

猜你喜欢

热点阅读