![](/img/trans.png)
[英]I don't know the difference between the two in the event handling process in React
[英]I don't know the difference
我刚刚开始学习函数。 这就是给我带来困难的原因。
const Func = () => { return () => { console.log('hello'); }; }; const innerFunc = Func(); innerFunc(); // 1. Func(); //2.
我不明白为什么“你好”没有出现在尝试使用 2 的控制台上。
函数的名称不是innerFunc 和Func 吗?
我不知道它们之间的区别。
对不起,我的英语不好。
Func()
返回一个函数,在您使用()
运行结果之前不会执行该函数,就像您使用1.
所做的那样。
通过做const innerFunc = Func();
,您正在将从Func
返回的函数分配给innerFunc
。 所以要调用它,你需要像这样运行它: innerFunc()
。
你的函数'Func'从内部返回另一个函数,所以当你调用Func()时,它会返回另一个你命名为'innerFunc'的函数,调用innerFunc将返回输出为hello。
当您尝试使用 Just 'Func()' 时,它只会返回您在 Func 中返回的另一个函数。
开始学习函数,看看
const Func = () => {
console.log('hello');
};
Func(); // logs hello to the console
你这里有一个函数内部的函数,它更复杂,不一定适合初学者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.