(1)回调函数的定义
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)回调函数的调用,一般为匿名函数,且有返回值
 add(1,2,function (v) {//回调函数有返回值
 if(v>0){
 alert("result>0")
 }else{
 alert("result<0")
 }
 })下载本文