const compose = (...fns) => value => fns.reverse().reduce((acc, fn) => fn(acc), value)
compose(
third,
second,
first
)("test")
//等于
third(second(first(test)))
本文介绍了一种在编程中使用高阶函数的方法——函数组合,并通过一个简单的示例展示了如何将多个函数串联起来形成新的函数。这种方法可以提高代码的复用性和可读性。
const compose = (...fns) => value => fns.reverse().reduce((acc, fn) => fn(acc), value)
compose(
third,
second,
first
)("test")
//等于
third(second(first(test)))
转载于:https://www.cnblogs.com/lieaqi/p/10614526.html

被折叠的 条评论
为什么被折叠?