维基百科中使用 Python 解释了 Point-Free 风格或默认编程。
def example(x):
y = foo(x)
z = bar(y)
w = baz(z)
return w
和..
def flow(fns):
def reducer(v, fn):
return fn(v)
return functools.partial(functools.reduce, reducer, fns)
example = flow([baz, bar, foo])
如何使用 JS 以最简单易懂的概念形式演示这种效果?
最佳答案
可以很容易地转换成 JS:
function example(x) {
const y = foo(x);
const z = bar(y);
const w = baz(z);
return w;
}
...和
function flow(fns) {
function reducer(v, fn) {
return fn(v);
}
return fns.reduce.bind(fns, reducer);
}
const example = flow([baz, bar, foo]);
关于javascript - 如何在JS中演示简单的无点风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55395719/