-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,4 @@ plugins/ | |
webpack.config.dump.js | ||
tmp/ | ||
*todo* | ||
test.js | ||
临时暂存待办.md |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
function compose(...fns) { | ||
var start = fns.length - 1; | ||
return function () { | ||
var i = start; | ||
var result = fns[start].apply(this, arguments); | ||
while (i--) result = fns[i].call(this, result); | ||
return result; | ||
}; | ||
} | ||
|
||
// const _pipe = (f, g) => (...args) => g.call(null, f.apply(null, args)) | ||
// const compose = (...fns) => fns.reverse().reduce(_pipe) | ||
|
||
|
||
// const _pipe = (f, g) => (...args) => g(f(...args)) | ||
// const compose = (...fns) => fns.reverse().reduce(_pipe) | ||
|
||
|
||
// test | ||
function f1(a, b) { return a + b } | ||
function f2(a) { return 2 * a } | ||
function f3(a) { return a * a } | ||
// let f = compose(f1, f2, f3) | ||
let f = compose(f3, f2, f1) | ||
console.log(f(1, 2)) // 36 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
function compose(...fns) { | ||
var start = fns.length - 1; | ||
return function () { | ||
var i = start; | ||
var result = fns[start].apply(this, arguments); | ||
while (i--) result = fns[i].call(this, result); | ||
return result; | ||
}; | ||
} | ||
|
||
// const _pipe = (f, g) => (...args) => g.call(null, f.apply(null, args)) | ||
// const compose = (...fns) => fns.reverse().reduce(_pipe) | ||
|
||
|
||
// const _pipe = (f, g) => (...args) => g(f(...args)) | ||
// const compose = (...fns) => fns.reverse().reduce(_pipe) | ||
|
||
|
||
// test | ||
function f1(a, b) { return a + b } | ||
function f2(a) { return 2 * a } | ||
function f3(a) { return a * a } | ||
// let f = compose(f1, f2, f3) | ||
let f = compose(f3, f2, f1) | ||
console.log(f(1, 2)) // 36 |