手动实现一个简易版的Promise
function PromiseSimple (excutor) { let _this = this let _status = 'pending' let successCallBack = undefined let failCallBack = undefined excutor(resolve.bind(_this), reject.bind(_this)) function resovle (params) { if (_this._status === 'pending') { _this._status = 'full' _this.successCallBack(params) } } function reject (params) { if (_this._status === 'pending') { _this._status = 'fail' _this.failCallBack(params) } } } PromiseSimple.prototype.then = function (full, fail) { this.successCallBack = full this.failCallBack = fail }相关文章
- 04-12「每日一题」面试官问你对Promise的理解?可能是需要你能手动实现各个特性
- 04-1225.Promise原理及实现
- 04-12JS之路:Promise
- 04-12JS Promise 迷你书 笔记
- 04-12js 前端 异步 async await promise resolve reject generator yield setTimeout 请求 原理 面试
- 04-1225.Promise原理及实现
- 04-12Promise A+ 规范【中文版】
- 04-12手写 Promise 符合 Promise/A+规范
- 04-12Promise详解二(解读Promise规范+手写Promise)
- 04-12移动端适配rem.js