顶尖的赣州网站建设seo引擎优化平台培训
一、Promise
Promise 是一个 Es 6 提供的类,目的是更加优雅地书写复杂的异步任务。可以解决嵌套式的回调地域问题,Promise 将嵌套格式的代码变成了顺序格式的代码。
//回调地域
setTimeout(function () {console.log("红灯");setTimeout(function () {console.log("绿灯");setTimeout(function () {console.log("黄灯");}, 1000);}, 2000);
}, 3000);//promise.then链式调用解决回调地域问题, Promise 将嵌套格式的代码变成了顺序格式的代码。
new Promise(function (resolve, reject) {setTimeout(function () {console.log("red");resolve();}, 3000);
}).then(function () {return new Promise(function (resolve, reject) {setTimeout(functio