function sleep(delay){
return function(){
return new Promise(function(resolve, reject){
setTimeout(resolve, delay);
});
}
}
//延时执行
var promise = new Promise(function(resolve){
console.log('1 do something');
resolve();
}).then(sleep(2000)).then(function(){
console.log('2 after sleep 2000');
}).then(sleep(2000)).then(function(){
console.log('3 after sleep 2000');
}).then(sleep(2000)).then(function(){
console.log('4 after sleep 2000');
})