Promise学习笔记

69 阅读1分钟

@[toc]

1,创建promise

const promise = new Promise(function(resolve, reject){
	setTimeout(function(){
		resolve("ok");
	},1000);
})
promise.then(function(msg){
	console.log(msg);
})

2, then

两个参数。 第一个是resolve回调,第二个是reject回调。

promise.then(function(){}[, function(){}])

3,Promise.all()

4,Promise.allSettled()

5,Promise.any()

6,Promise.catch()

7,Promise.finally()

不论Promise执行结果如何,都会执行finally

8,Promise.race()

9,参考资料link.