手写一个自己的Promise
话不多说,直接上代码 Promise手写 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 function MyPromise(executor){ let self = this self.status='pending' self.value=undefined self.reason = undefined self.fullfilledCallbacks=[] self.rejectedCallbacks=[] function resolve(value){ if(self.status==='pending'){ self.status = 'fullfilled' self.value