Implementing #javascript Promise in 70 lines of code!
▻https://hackernoon.com/implementing-javascript-promise-in-70-lines-of-code-b3592565af0f?source=
Ever wondered how JavaScript Promise works internally? Obviously there is some native browser support involved, right? Nope! We can implement the Promise interface using pure JavaScript, examples are libraries like Bluebird or Q. And it’s much simpler than you may think, we can do so in only 70 lines of code! This will help with gaining a deeper insight into #promises by demystifying the underlying formation. Can also serve as a good #interview question, if you are an evil employer (don’t be!). Let’s dig into it!First thing that you notice is that a Promise has three states, so should we:▻https://medium.com/media/bacc1e31f78f0a08c3b6a2e7654837f2/hrefMAKE new Promise() GREAT AGAIN!Using a class sounds reasonable since we should be able to create a new Promise(). Ah, and let’s name our class (...)