Last active
June 10, 2019 11:05
-
-
Save kiinlam/4bb947e0d8986b954273feb04796d6c6 to your computer and use it in GitHub Desktop.
es6实现pipeline效果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe(data, ...args) { | |
return args.reduce((r, f) => f(r), data); | |
} | |
//test | |
function f1(a) { | |
a.pop(); | |
return a; | |
} | |
function f2(a) { | |
return a.reverse() | |
} | |
//[1,2,3]经过两个function的处理后,输出结果 | |
pipe([1,2,3], f1, f2) // => [2,1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用Proxy实现: