回调函数

//接收回调函数的函数
function add(x,y,fn){
    this.x = x||1;
    this.y = y||1;
    var x = this.x;
    var y = this.y;
    if(fn){
        fn(x,y)//向回调函数传值
    }
}

//在回调函数里面进行操作
add(2,3,function(x,y){
    //对回调函数传过来的值进行操作
    console.log(x*y)
});
原文地址:https://www.cnblogs.com/wvvv/p/5227301.html