How does Promise in javascript work under the hood? My Promise implementation doesn't work the same
问题 I am a newbie to JS and I am trying to understand how Promise should work under the hood. Here is a custom implementation that looks reasonably good to me: class MyPromise { constructor(executor) { this._resolutionQueue = []; this._rejectionQueue = []; this._state = 'pending'; this._value; this._rejectionReason; try { executor(this._resolve.bind(this), this._reject.bind(this)); } catch (e) { this._reject(e); } } _runRejectionHandlers() { while(this._rejectionQueue.length > 0) { var rejection