We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
实现一个 Promise
The text was updated successfully, but these errors were encountered:
Promise采用面向对象的方式封装了回调函数,可以将回调金字塔改为链式调用。Promise是一种规范,ES6选择了Promise A+的方案
// 简易版 class Promise { constructor(init) { this.PromiseStste = 'pending'; let resolve = (val) => { if (this.resolveCallBack) { this.PromiseStste = 'fulfilled'; this.resolveCallBack(val); } } let reject = (val) => { if (this.resolveCallBack) { this.PromiseStste = 'reject'; this.rejectCallBack(val); } } if (init) { init(resolve, reject); } } then(onFulfill, onReject) { this.resolveCallBack = onFulfill; this.rejectCallBack = onReject; return this } }
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: