在吃这件事上,不只是中国人特有的的,更不是广东人特有的,而是人类共通的,为了果腹,为了解决威胁,人类会吃。
月度归档:2017年12月
浏览器端 async/await 还是有点代价的
对于下面这段 js
function async3() {
createPromise()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
.finally(() => {
console.log('finally');
});
}
其对应 async/await
版本是
async function async2() {
try {
const ret = await createPromise();
console.log(ret);
} catch (e) {
console.error(e);
} finally {
console.log('finally');
}
}
经 babel 转为 ES5 后,除了必要的 babel-polypill,会生成以下代码,其中 _asyncToGenerator
不会多次生成。
写法上直观了的,但在浏览器端,还是有些代价,生成的代码会多出不少。