赞
踩
下面直接上代码,实现分析实现promise、call、apply、bind原理实现,如有问题欢迎指点。
// prmoise实现 const PENDING = 'pending' const RESOLVED = 'resolved' const REJECTED = 'rejected' function MyPromise(fn) { const that = this that.state = PENDING that.value = null that.resolvedCallbacks = [] that.rejectedCallbacks = [] // 待完善resolve和reject函数 // 待完善fn执行函数 } function resolve(value) { const that = this if (that.state === PENDING) { that.state = RESOLVED that.value = value that.resolvedCallbacks.map(cb => cb(thst.value)) } } function reject(value) { const that = this if (that.state ===
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。