简体   繁体   English

这个函数在javascript中是如何工作的?

[英]How does this function work in javascript?

I need your help in understanding below codes.我需要您帮助理解以下代码。

map<U>(mapFunction: (task: Task, index: number)=> U) {
        return this.tasks.map(mapFunction);
}

forEach<U>(mapFunction: (task: Task, index: number)=> U) {
        return this.tasks.forEach(mapFunction);
 }

Can anyone explain me how these codes work.谁能解释一下这些代码是如何工作的。 I'm trying to search it but failed.我试图搜索它但失败了。 I know there is a term for using these codes.我知道有使用这些代码的术语。 I just don't get the term我只是不明白这个词

It's nothing but fat arrow in type script.它只不过是打字稿中的粗箭头。 this gets convert to java script using transpilers and Babel is one of the popular for this job这使用转译器转换为 java 脚本,而 Babel 是这项工作的流行之一

more information on fat arrow 有关胖箭头的更多信息

Here is at least some information if not all.这里至少有一些信息,如果不是全部的话。

Link to explanation 链接到解释

It's called a它被称为一个

javascript map function javascript地图功能

In short: It itererates over array elements and calling functions on them简而言之:它迭代数组元素并在它们上调用函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM