1.

function sleep(duration) {
    return new Promise(function(resolve, reject) {
        console.log("b");
        setTimeout(resolve,duration);
    })
}
console.log("a");
var s = sleep(2000);
setTimeout(function(){console.log("wait")},2000);
s.then(()=>console.log("c"));

来源:https://blog.csdn.net/nana_9457/article/details/88224472

2.


(function test(){
	setTimeout(function(){
		console.log(4);
	},0)
	new Promise(function(resolve){
		console.log(1);
		for(var i=0;i<1000;i++){
			i==999&&resolve();
		}
		console.log(2)
	}).then(function(){
		console.log(5)
	});
	console.log(3);
})()//1,2,3,5,4

来源:https://blog.csdn.net/qq_41047322/article/details/81451734

作者 铁血 汉子 2019年10月28日
2024/11/21/03:52:02pm 2019/10/28/1:51:34
0 1167