不使用 ES6 Promise
嵌套两个 setTimeout 回调函数
setTimeout(function(){console.log('hello'); // 一秒后输出 “hello”setTimeout(function(){console.log('world'); // 两秒后输出 “world”}, 1000)
}, 1000);
使用 ES6 Promise ,实现以上相同效果
var waitSecond = function() {return new Promise(function(resolve, reject) {setTimeout(resolve, 1000);});
}waitSecond().then(function(){console.log('hello'); // 一秒后输出 “hello”return waitSecond();
}).then(function(){console.log('world'); // 两秒后输出 “world”
});