Replies: 13 comments 1 reply
-
有 |
Beta Was this translation helpful? Give feedback.
-
这样是否可以? async sum (a, b) => { /* do some async works */ } |
Beta Was this translation helpful? Give feedback.
-
我的意思是,你还需要区分 |
Beta Was this translation helpful? Give feedback.
-
感觉这个还好吧, |
Beta Was this translation helpful? Give feedback.
-
其实 所以具体为什么不支持可能还需要考证( |
Beta Was this translation helpful? Give feedback.
-
其实我希望有 named lambda 的主要原因是方便自引用。 const callback = () => {
console.log(Date.now() - this.startTime)
setTimeout(callback, 1000)
}
setTimeout(callback, 10000) v.s. const ctx = this
setTimeout(function callback () {
console.log(Date.now() - ctx.startTime)
setTimeout(callback, 1000)
}, 10000) v.s. setTimeout(callback () => {
console.log(Date.now() - this.startTime)
setTimeout(callback, 1000)
}, 10000) |
Beta Was this translation helpful? Give feedback.
-
@Alan-Liang 没错,自引用或者叫递归调用,也是一个能被优化的场景 |
Beta Was this translation helpful? Give feedback.
-
递归的话在尾递归优化落实之前还是算了吧😂 随便写点什么都能爆栈…… |
Beta Was this translation helpful? Give feedback.
-
那倒不至于,很多场景还是需要递归的,比如遍历树、图等,爆栈属于自己代码写得有问题吧。 这可能不属于这个话题下讨论的东西。 |
Beta Was this translation helpful? Give feedback.
-
期望支持,错误便于跟踪 |
Beta Was this translation helpful? Give feedback.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
-
杨健找到了一些老的讨论:https://esdiscuss.org/topic/named-arrow-functions 看起来主要问题还是当初命名箭头函数在语法上和 马后炮来说,如果有 async do expression,那么其实不需要异步箭头函数,直接 总得来说,还是命名的需求不够强。我的意思是,你总能通过单独把箭头函数赋值一个变量来解决(无论是自引用、递归还是调试所需的名称),或者包一层来命名( |
Beta Was this translation helpful? Give feedback.
-
为了程序的可读性,我们可能需要为箭头函数进行命名。
现在我们的做法与原来的
function
匿名函数一样,将箭头函数赋给一个标识符或对象键,如:但当我们在一个链式调用或 pipeline 中,我们就没法为函数命名了,如 Lodash Flow:
在讨论中的 Pipeline(在此不展开讨论最后是否用这个方案)我们也有类似的问题:
我们是否可能直接在箭头函数前面为此箭头函数命名?就像这样:
这个是否有较高的技术实现上的难度或设计上的冲突?
Beta Was this translation helpful? Give feedback.
All reactions