Skip to content

Instantly share code, notes, and snippets.

@ShenTengTu
Created July 1, 2017 09:34
Show Gist options
  • Save ShenTengTu/3ad5b8d3d5401b2b2b3816f955adddcf to your computer and use it in GitHub Desktop.
Save ShenTengTu/3ad5b8d3d5401b2b2b3816f955adddcf to your computer and use it in GitHub Desktop.
Execute functions sequentially with array
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.");
}
@ShenTengTu
Copy link
Author

You can see the JSFiddle :
https://jsfiddle.net/ShenTengTu/q3d1ew6r/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment