Thunks
| javascriptWatched some videos giving an overview of asynchronous JavaScript, all taught by Kyle Simpson. What’s a thunk?
“Time is the most complex factor of state in your program.”
A thunk is simply a function that uses closure to keep track of some value(s) and returns them when the thunk is called.
The code snippet below is a synchronous thunk. It feeds arguments to babyRage() and returns it. Every single time we call thunk(), it will always give the same legitamate reasons for what causes rage.
Next is an asynchronous thunk. This thunk takes a callback, gives a couple reasons for rage, and hands babyRageAsync() the callback. Same as our first thunk, except we must pass a callback to our thunk to retrive its value.
What is the significance? TO BE CONTINUED!