【问题标题】:What does the "=>" symbol mean in ionic framework? [duplicate]离子框架中的“=>”符号是什么意思? [复制]
【发布时间】:2019-02-09 23:29:09
【问题描述】:

我参考了 ionic 网站上的 this 文档,以将 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' 方法似乎有一个变量后跟"=>" 符号。这个符号是否具有一般含义,还是因方法而异?究竟是什么意思?

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

【问题讨论】:

    标签: javascript android angular typescript ionic-framework


    【解决方案1】:

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

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

    这是一个将令牌作为参数并记录它的函数。

    参数由then 函数在调用您的 lambda 表达式时传递。有道理吗?

    【讨论】:

      猜你喜欢
      • 2015-05-04
      • 2015-02-13
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 2011-02-27
      • 2014-12-06
      • 2018-01-20
      • 2016-10-31
      相关资源
      最近更新 更多