const handleFiles = () => {
return async handle => {
let result;
result = 'hello';
return result;
};
};
handleFiles().then(result => console.log(result)).catch(console.log(e));
为什么这个脚本不起作用?
未捕获的类型错误:handleFiles(...).then 不是函数
const handleFiles = () => {
return async handle => {
let result;
result = 'hello';
return result;
};
};
handleFiles().then(result => console.log(result)).catch(console.log(e));
为什么这个脚本不起作用?
未捕获的类型错误:handleFiles(...).then 不是函数
问题是它
handleFiles返回一个函数,而不是Promisea,它有一个then.解决方案是要么调用返回的函数,要么返回调用的结果:
这是您承诺的功能的样子
在 resolve 中,为 then 传递一个参数,在 reject 中,为 catch 传递一个参数
执行: