1.这里说得fn个参数,我知道应该跟arguments和在函数里面用return function(){}这种方式来写,但是就是写不明白
function add(a,b){
return a+b;
}
function square(a){
return a*a;
}
function plusOne(c){
return c+1;
}
//var result = plusOne(square(add(1,2))); //这种的直接的转化成下面的不会
//alert(result);
var addSquareAndPlusOne = composite(add,square,plusOne);
function composite(add,square,plusOne){
return function(){
//这里怎么写呢?谢谢指导
}
}
addSquareAndPlusOne(1,2);
第一种写法:
第二种写法:
改进了一下 @小明 的代码,现在可以随意改变需要执行方法的顺序了,只需要保证有足够的参数就可以了
雷雷
通用一点的解,但是写的比较low...
我也来贴一个比较low的的写法,希望多多指正
把 @止水 同学的两种写法结合一下: