"符号在 ionic 框架中意味着什么?-6ren"> "符号在 ionic 框架中意味着什么?-这个问题已经有答案了: What does arrow function '() => {}' mean in Javascript? [duplicate] (2 个回答) 已关闭 4 年前。 我提-6ren">
gpt4 book ai didi

javascript - "=>"符号在 ionic 框架中意味着什么?

转载 作者:行者123 更新时间:2023-12-03 01:12:01 25 4
gpt4 key购买 nike

我提到了this ionic 网站上的文档,将 firebase 与我的移动应用程序集成。

this.firebase.getToken()
.then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
.catch(error => console.error('Error getting token', error));

this.firebase.onTokenRefresh()
.subscribe((token: string) => console.log(`Got a new token ${token}`));

如上面的代码所示,'then' , 'catch''subscribe'方法似乎有一个变量后跟 "=>"象征。该符号是否具有通用含义,还是因方法而异?具体是什么意思?

编辑:由于这个问题被其他人标记为重复,我认为这是我不知道的 typescript 中的一个新功能。在 JavaScript 中,我一直使用旧式方法,正如答案之一所指出的那样。不过,这可能会对像我这样的人有所帮助。

最佳答案

它是一个 lambda 表达式,它基本上是一个函数,作为参数传递给 thensubscribe 等方法,并在这些方法接收到消息后调用排放。

token => console.log(` token 是 ${token}`)

它是一个以标记作为参数并记录它的函数。

then 函数调用 lambda 表达式时,该参数由该函数传递。如果这有意义吗?

关于javascript - "=>"符号在 ionic 框架中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52174616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com