【发布时间】:2020-10-05 05:30:42
【问题描述】:
我对 TypeScript 有点陌生,不过我对 Java 很了解。在那里,每当需要满足功能接口时,最常见的方法是使用 lambda 表达式 (->) 或方法引用 (::)。
Lambda 表达式在两种语言之间似乎是等价的(如果我错了,请纠正我)。有没有办法利用方法引用?
当目标是实现这一点时:
this.entryService.getEntries()
.subscribe(entries => this.listUpdateService.send(entries));
有没有办法使用函数引用?下面的做法似乎是错误的,因为send 没有在this.listUpdateService 的范围内执行。 (顺便说一句,它在哪个范围内执行?)
this.entryService.getEntries()
.subscribe(this.listUpdateService.send);
【问题讨论】:
标签: java typescript lambda scope method-reference