Preface
Before you read, I hope you should have some hand-on experience of the Promise mechenism in javascript. And you should also bear in mind that Promise is not mysterious at all, which is just a trick invented by some functional programming enthusiast. In the following part, I will unmask the magic of this magic Promise
Anatomy
Recap
Let’s coin a simple promise example first
1 | function getUserId() { |
Prototype for Promise
1 | function Promise(fn) { |