961
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);