1、promise可以处于等待被赋值的等待态(pending),可以给出值并转换为解决态(resolved)。
2、一旦promise被一个值resolve丢失,它将始终保持这个值不再被resolve丢失。
实例
functionPromise(fn){ varstate='pending'; varvalue; vardeferred; functionresolve(newValue){ value=newValue; state='resolved'; if(deferred){ handle(deferred); } } functionhandle(onResolved){ if(state==='pending'){ deferred=onResolved; return; } onResolved(value); } this.then=function(onResolved){ handle(onResolved); }; fn(resolve); }原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容