博客
关于我
回调函数(callback function)
阅读量:376 次
发布时间:2019-03-05

本文共 927 字,大约阅读时间需要 3 分钟。

计算机编程中,”回调“是可执行代码的参考,或者是一段可执行程序,”回调“被当做参数传入另外的代码中。这种”回调“机制允许软件底层代码调用上层定义的函数。

很多人对”回调“感到困惑是因为这个”回调“这个名字在作怪。

一个回调方法可以作为参数传入另外一个方法中,回调方法的执行是某些事件所激发的。参数的”调回“本质是,一旦父方法执行完,作为参数的回调方法(回调函数)就会被调用。也就是说父方法调回执行作为参数传过来的方法。

//An innocuous looking method which will become known as a callback method//because of the way in which we will invoke it.function meaningOfLife() {    log("The meaning of life is: 42");}//An innocuous looking method which just takes an int and prints it to screen, and takes a function reference to be executed when printANumber completesfunction printANumber(int number, function callbackFunction()) {    print("The number you provided is: " + number);}function event() {   printANumber(6, meaningOfLife());}

The number you provided is: 6The meaning of life is: 42

之所以叫回调函数,是因为在那些含有指针概念的编程语言中有这样的叫法。如果你的编程语言没有指针概念,那么就可以不去关心回调函数的执行细节。仅仅把它理解成一个函数作为参数被另外一个函数调用就成了。因此,无论父函数什么时候被调用(不论什么情况:按钮点击,定时器到时),当父函数执行完后,回调函数就会被调用。

转载地址:http://zcuwz.baihongyu.com/

你可能感兴趣的文章
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>