Created
July 1, 2017 09:34
-
-
Save ShenTengTu/3ad5b8d3d5401b2b2b3816f955adddcf to your computer and use it in GitHub Desktop.
Execute functions sequentially with array
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
var jsList = ["inline.js","polifill.js","vendor.js","main.js"]; | |
var seq = jsList.reduceRight(reducefn,donefn); | |
seq("Start"); | |
function mockExcuteJs(js,fn){ | |
console.log(`Execute ${js}`); | |
fn("Execute "+js+" done."); | |
} | |
function reducefn(fn,js) { | |
return function (s){ | |
console.log(s); | |
mockExcuteJs(js,fn); | |
}; | |
} | |
function donefn(s) { | |
console.log(s); | |
console.log("All done."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can see the JSFiddle :
https://jsfiddle.net/ShenTengTu/q3d1ew6r/