JS之路:Promise
作者:互联网
手动实现一个简易版的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 }标签:status,function,let,successCallBack,之路,JS,Promise,._,params 来源: https://www.cnblogs.com/fontyou/p/14148006.html