Simply put, callback function: that is, the function to be executed.
(1) Definition of callback function
##
function add(x,y,fn) { /* * this.x this.y:属于add类的全局变量的定义 * */ this.x=x||1; this.y=y||1; if(fn){ /*判断是否有回调函数,有的话执行传入的函数(传入参数)*/ fn(this.x+this.y); } }
2) The callback function is usually an anonymous function with a return value
## add(1,2,function (v) {//回调函数有返回值
if(v>0){
alert("result>0")
}else{
alert("result<0")
}
})
The above is the detailed content of The meaning of javascript callback function. For more information, please follow other related articles on the PHP Chinese website!