我正在尝试创建一个返回另一个函数的“三次”函数。
我有以下代码:
const thrice = (inputFunc) => {
return inputFunc()
}
let eight;
eight = thrice(() => {
return 8;
});
const value = eight();
value
我的期望是该值将等于:8。根据我的测试规范,它应该等于 8。
但是当我运行我的代码时,它返回: TypeError: eight is not a function
我究竟做错了什么?我的预感是我应该return inputFunc
在三次函数中做。但我从概念上不明白为什么。
请注意
thrice(() => {
return 8;
});
不是函数而是函数调用,所以eight
等于 8。所以要解决这个问题:
eight = ()=> thrice(() => {
return 8;
});
// or
eight =function(){ thrice(() => {
return 8;
});};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句