const compose = f => g => x => f(g(x));
const f = compose (x => x * 4) (x => x + 3);
f(2) // 20
求一个化简后的compose!!!!!!.......还有为什么f(2)等于8
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
地址
可能给compose的参数换个名字更阅读一些?
三次调用再拆为
compose(function(x) {return x * 4;})即参数a为函数function(x) {return x * 4;}内部a(b(c))相当于对a调用内部参数x为b(c),得到function(b){return function(c){return b(c)*4}}此时
f1 = function(b){return function(c){return b(c)*4}}同样对f1的调用f1(function(x) {return x + 3;})相当与参数b为function(x){return x+3},内部b(c)相当于将c作为参数传入b中,得到function(c){return (c+3)*4}此时
f2=function(c){return (c+3)*4},f2(2)=20有点绕,可以拿笔和纸写一下。