下面是一个简单的promise调用
new Promise(function(success,){ setTimeout(function(){success()},1000); }).then(function(){ console.log(1) });
可以看到,控制台能够输出1
Promise 的then方法可以做到回调功能,但是如果是这种情况呢?
function test(back){ setInterval(function(){back()},1000) } test(function(){ console.log(1); });
//可以不停的输出1
而如果用promise做不到:
new Promise(function(success,){ setInterval(function(){success()},1000); }).then(function(){ console.log(1) });
Promise 除了then,catch还有隐藏的高级功能么?
慕斯709654
胡子哥哥
相关分类