我有一个理解箭头函数的问题,我知道箭头函数的类型是这样的()=>,但我想知道我们在函数内部输入的箭头函数是如何工作的
喜欢
app.listen(3000 , () => console.log('foo'));我想知道热监听函数调用箭头函数?以及它如何在没有任何名称的情况下调用箭头函数
那么,如果我想创建一个以箭头函数为参数的函数,我该怎么做呢?
发布于 2019-07-05 00:01:35
这称为回调函数,请查看MDN以获取文档:https://developer.mozilla.org/en-US/docs/Glossary/Callback
该函数在父函数的参数中命名。
function myFunc(callbackFunc) {
//do stuff!
console.log("in parent func");
callbackFunc(); //calls the callback function passed as a param
console.log("Callback done!"); //If there is async code in your callback function, this may happen BEFORE the callbackFunc() is finished. A common gotcha to watch out for.
}
myFunc(() => { console.log("Doing the callback") });下面是ExpressJS如何使用回调函数:https://expressjs.com/en/guide/using-middleware.html
发布于 2019-07-05 00:05:36
除了functions and arrow function之间的重要区别之外,它们非常相似。
未命名:
app.listen(3000 , () => console.log('foo'));
// or
app.listen(3000 , function() { console.log('foo') } );命名:
function aaa() { ... }
// or
const aaa = () => { ... }https://stackoverflow.com/questions/56891331
复制相似问题