手写简单的promise
const PENDING = 'pending';
const RESOLVED = 'resolved';
const REJECTED = 'rejected';
function newPromise(fn){
const _that = this;
_that.state = PENDING;
_that.value = null;
_that.resolvedCallbacks = [];//用来保存then中的回调
_that.rejectedCallbacks = [];//用来保存then中的回调
function resolve(value){
if(value instanceof newPromise){
value.then(resolve,reject);
手写简单的promise最先出现在Python成神之路。
共有 0 条评论