当前位置:网站首页>什么是回调函数,对于“回”字的理解
什么是回调函数,对于“回”字的理解
2022-07-26 12:08:00 【百学成瘾】
回调函数
网上解释了很多,却把“回”解释为“回头”,很是难懂,在我看来,“回”理解为“反过来”更好一点,意为角色互换的调用。
通俗解释一下:
程序分为应用程序和库函数
在开发应用程序时我们往往会去调用库函数,这时候如果库函数的参数要求传入一个你自己定义好的函数,库函数稍后会反过来调用你写的函数,而这个过程由
你调用库函数变成了库函数调用你写的函数,在我看来,这个角色的互换才是名为“回调函数”的本质所在。
从另一个角度来看,应用程序属于高层,库函数属于底层,一般来说,是高层调用底层,而现在反过来则是底层调用高层,这种层次角色的变换也体现了“回”字反过来调用的意思
(该图为网图,随便截了一张,来源未知,可以帮助理解一下调用过程)

意义:
理解了回调函数的本质,他的意义显而易见,那就是将自己的代码嵌入到底层函数(或是库函数)中,因为底层函数(或是库函数)是在应用程序开发之前封装好的,有些功能需要因人而异,怎么办呢? 所以只能保留接口,把自定义函数以参数的形式传进来,库函数再反过来去调用自定义函数,而回调函数恰好就是这种形式的体现。
ps:之前听说过钩子函数(hook),没太懂,可能也是能达到类似的效果吧。
边栏推荐
- Codepoint 58880 not found in font, aborting. Flutter build APK reports an error
- Pytorch深度学习快速入门教程 -- 土堆教程笔记(一)
- 使用fastJson中的JSONObject对象简化POST请求传参
- Y9000p2022 reinstallation win10 problem
- Use the jsonobject object in fastjason to simplify post request parameter passing
- Fineos announced the open registration of grouptech connect activities in 2022
- Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum
- 详解勒让德变换与共轭函数
- 羽毛球馆的两个基础设施你了解多少?
- Pytest interface automated test framework | fixture call fixture
猜你喜欢
![[Anhui University] information sharing of postgraduate entrance examination and re examination](/img/71/258b6b740d2c0e12d77e30f2df8a6e.jpg)
[Anhui University] information sharing of postgraduate entrance examination and re examination

儿童玩乐场所如何运营?

RFID的工作原理

了解string类

JSJ-3/AC220V时间继电器

Pytest interface automation test framework | pytest configuration file

Use and optimization of MySQL composite index (multi column index)

10. 509. Introduction to PKCs file format

【2243】module_param.m

How much do you know about the two infrastructures of the badminton stadium?
随机推荐
PyCharm是真的强
DS-112时间继电器
uniapp h5、app引用外部在线js
海外APP推送(下篇):海外厂商通道集成指南
Map函数统计字符出现的次数
Transactional事务传播行为?
pytest接口自动化测试框架 | 使用多个fixture
Pytest interface automation test framework | pytest configuration file
pytest接口自动化测试框架 | pytest的setup和teardown函数
Access数据库无法连接
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
Redisson分布式锁流程详解(二)
Why BGP server is used in sunflower remote control? Automatic optimal route and high-speed transmission across operators
Codepoint 58880 not found in font, aborting. Flutter build APK reports an error
【活动早知道】LiveVideoStack近期活动一览
敲黑板画重点:七种常见“分布式事务”详解
2022.7.23 ------ leetcode. Jianzhi offer.115
MySQL之数据查询(聚合函数)
RFID的工作原理
HTAP comes at a price