码迷,mamicode.com
首页 > 其他好文 > 详细

Async

时间:2017-05-24 18:27:48      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:time   eve   window   on()   onload   async   settime   ntb   set   

window.onload = function(){
document.getElementById(‘bottom‘).addEventListener(‘click‘, function(){
alert(11);
});
}

var sleep = function (time) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
let data = ‘db‘;
resolve(data);
}, time);
})
};

var sleepAgain = function (time) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve();
}, time);
})
};

var start = async function () {
// 在这里使用起来就像同步代码那样直观
console.log(‘start‘);
let result = await sleep(3000);
console.log(result);
console.log(‘again‘);
await sleepAgain(3000);
console.log(‘end‘);
};

start();

Async

标签:time   eve   window   on()   onload   async   settime   ntb   set   

原文地址:http://www.cnblogs.com/winyh/p/6900220.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!