//resolve和rejectfunction Promise(fn) {this.status = 'pending'this.value = ''const _this = thistry {fn(resolve, reject)} catch (e) {reject(e)}function resolve(value) {_this.value = value_this.status = 'resloved'}function reject(value) {_this.value = value_this.status = 'rejected'}}//then方法实现Promise.prototype.then = function (onReslved, onRejected) {if (this.status === 'resolved') {onReslved(this.value)}if (self.status === 'rejected') {onRejected(this.reason);}}
