Created
July 17, 2018 12:21
-
-
Save LB-Digital/8b7dd3d0b8f09ed4b7452cff11aa71b9 to your computer and use it in GitHub Desktop.
Method for chaining functions in JS, avoiding an ungodly callback pyramid
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 chain = [ | |
()=>{ | |
console.log('chain1111'); | |
return chain.shift()(); | |
}, | |
()=>{ | |
console.log('chain22222'); | |
return chain.shift()(); | |
}, | |
()=>{ | |
console.log('chain3333'); | |
return chain.shift()(); | |
}, | |
()=>{ | |
console.log('chain44444'); | |
console.log('DONE'); | |
} | |
]; | |
chain.shift()(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment