Implement chained calls to the Promise Then methods

Const PEDDING = 'PEDDING' const RESOLVE = 'RESOLVE' const REJECT = 'REJECT' // Promise has three states const handlePromise = (result,newPromise,resolve, Reject)=>{if(result == newPromise){throw new Error(' I can't return myself ')} if(typeof result === = 'object' && typeof result ! = = null | | typeof result = = = 'function') {/ / whether the result is then method const then = result. Then the if (typeof then = = = 'function') { Call (result,r=>{// Continue calling yourself, R = res handlePromise(r,newPromise,resolve, },e=>{reject(e)})}else{resolve(result)}}else{// class newPromise} class newPromise {// [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] OnRejectArr = [] constructor(exc) { const resolve = (result) => { if (this.status === PEDDING) { this.result = result this.status = RESOLVE this. / / execution's publisher onResolveArr. The map ((fn) = > fn ())}} const reject = (reason) = > {the if (this. The status = = = PEDDING) { This. reason = this.status = REJECT // release this. onrejectar. map((fn) => fn())}} exc(resolve, this. onrejectar. map((fn) => fn()))} exc(resolve, this. onrejectar. map((fn) => fn()))}) reject) } then(onResolve, onReject) { const newPromise = new NewPromise((resolve, reject) => { if (this.status === RESOLVE) { setTimeout(() => { const result = onResolve(this.result) handlePromise(result,newPromise,resolve, reject) }, 0) } if (this.status === REJECT) { setTimeout(() => { const result = onReject(this.reason) handlePromise(result,newPromise,resolve, reject) }, 0)} if (this.status === PEDDING) {this.onresolvearr.push (() => {const result = onResolve(this.result) handlePromise(result,newPromise,resolve, reject) }) this.onRejectArr.push(() => { const result = this.onReject(this.reason) handlePromise(result,newPromise,resolve, reject) }) } }) return newPromise } } // let yan = new Promise((resole, Reject) = > {/ / resole (' uncle yan really handsome ') / /}) / / yan. Then (res = > {/ / console log (res) / /}) let newYan = new NewPromise((reject, reject) => {setTimeout(() => {return '1111'}, 3000) }) newYan .then((res) => { console.log(res) return {name:'yan'} }) .then((res) => { console.log(res) }) console.log(11111111)