【问题标题】:Unexpected Token in Firebase functionsFirebase 函数中出现意外的令牌
【发布时间】:2017-08-04 10:30:44
【问题描述】:

当我尝试上传 Firebase 函数时出现以下错误

解析函数触发器时出错。

/private/var/folders/_5/96_hf2sx4dj69gzfm6bz9fl80000gn/T/fbfn_62815Dgk529e7Q94f/index.js:94 如果 (current_value - 1) >= 0 { ^^

SyntaxError: Unexpected token >=

代码如下

exports.countFollowing2 = functions.database.ref('/{pushId}/following/')
    .onDelete(event => {

      event.data.ref.parent.child('following_count').transaction(function (current_value) {

        if (current_value - 1) >= 0 {
          return (current_value - 1);
        }
        else{
          return 0;
        }

      });


    });

我假设我正在做一些愚蠢的事情并且它是一个简单的修复,但我无法弄清楚。提前感谢您的帮助!

【问题讨论】:

    标签: firebase firebase-realtime-database google-cloud-functions


    【解决方案1】:

    if (current_value - 1) >= 0 { 替换为if ((current_value-1) >= 0) {

    重要的区别是括号必须包含整个条件。这与 Swift(如果您来自该背景)不同,后者在条件本身周围加上括号是可选的。

    【讨论】:

    • 只是出于好奇:你是 Swift 背景的吗?
    • 是的,来自 swift
    猜你喜欢
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 2021-07-08
    相关资源
    最近更新 更多