
普通函数
返回 return 语句的值
function add(x, y) {
return x + y;
}
async函数
返回 Promise 对象
async function asyncPrint(value, ms) {
await timeout(ms);
console.log(value);
}
Generater 函数
返回同步 Iterator 对象
function* gen(x, y){
yield x + y;
}
异步 Generater 函数
返回异步 Iterator 对象
async function* asyncGenerator() {
const result = await doSomethingAsync();
yield 'Result: ' + result;
}




近期评论