1、promise可以处于等待被赋值的等待态(pending),可以给出值并转换为解决态(resolved)。
2、一旦promise被一个值resolve丢失,它将始终保持这个值不再被resolve丢失。
实例
function Promise(fn) { var state = 'pending'; var value; var deferred; function resolve(newValue) { value = newValue; state = 'resolved'; if(deferred) { handle(deferred); } } function handle(onResolved) { if(state === 'pending') { deferred = onResolved; return; } onResolved(value); } this.then = function(onResolved) { handle(onResolved); }; fn(resolve); }
以上就是js中Promise的状态探究,希望对大家有所帮助。更多js学习指路:js教程
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试