美文网首页
回调函数callback

回调函数callback

作者: 汉江岳 | 来源:发表于2021-03-10 16:41 被阅读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

相关文章

网友评论

      本文标题:回调函数callback

      本文链接:https://www.haomeiwen.com/subject/luvwqltx.html