Open EdwardZZZ opened 4 years ago
今天一个朋友问我 async 、await 是什么的语法糖,因为很多人说是 generator 的语法糖,他觉得是 Promise 的。
他是对的,是 Promise 的语法糖,generator 的语法糖是 * 和yield。
看如下代码你就懂了
const type = obj => Object.prototype.toString.call(obj).slice(8, -1); async function a() {} function *b() {} console.log(type(a)) console.log(type(b)) console.log(type(a())) console.log(type(b()))
今天一个朋友问我 async 、await 是什么的语法糖,因为很多人说是 generator 的语法糖,他觉得是 Promise 的。
他是对的,是 Promise 的语法糖,generator 的语法糖是 * 和yield。
看如下代码你就懂了