JS高阶函数

    function compose(f,g){
        return function(){
            console.log(arguments);
            return f.call(null,g.apply(null,arguments));
        }
    }
    var f = function(x){return x*x};
    var g = function(x,y){return x+y};

    var sg = compose(f,g);
    console.log(sg(1,2,3));

// argments [1,2,3]
// 结果输出 9

 

posted on 2018-03-02 15:35  花溪的小石头  阅读(169)  评论(0编辑  收藏  举报