回调函数

//接收回调函数的函数
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)
});

 

posted @ 2016-02-29 14:06  桃夭清华  阅读(144)  评论(0编辑  收藏  举报