1. while循环的方式
function sleep(ms) {
var start = Date.now(), expire = start + ms;
while (Date.now() < expire) ;
return;
}
2. 通过promise来实现
function sleep(ms){
return new Promise(function (resolve) {
setTimeout(resolve,ms)
})
}