我正试图创建一个函数,但当第一个函数是异步函数时,它会抛出错误function1(...) is not a function
,然而,如果我将异步函数作为最后一个函数传递,它工作得很好.
有人能告诉我为什么会发生这种事吗?以及如何正确地制作以异步函数开头的Curry函数?
感谢所有抽出时间的人.
//This one is throwing the error: function1(...) is not a function
async function function1(path) {
const fetchedElement = await fetchElement(path);
//(...)
return (msg) => {
console.log(msg);
};
}
function1('somepath.html')('my message');
//This one works fine, properly returning other function
function function2(path) {
return async (msg) => {
const fetchedElement = await fetchElement(path);
//(...)
console.log(msg);
};
}
function2('somepath.html')('my message');