【问题标题】:I cannot find this syntax error [closed]我找不到这个语法错误[关闭]
【发布时间】:2013-04-29 19:47:47
【问题描述】:

一旦有人向我指出这一点,我会觉得自己完全是个白痴,但是我遇到了一个语法错误,我无法弄清楚问题出在哪里。这是我的代码(错误出现在最后一行,但我怀疑是导致该错误的那一行):

// handle GCM notifications for Android
 function onNotificationGCM(e) {
 switch( e.event )
 {
     case 'registered':
     if ( e.regid.length > 0 )
     {
         // Your GCM push server needs to know the regID before it can push to this device
         // here is where you might want to send it the regID for later use.
         PushWoosh.appCode = "33F93-5013B";
         PushWoosh.register(e.regid, function(data) {
                     alert("PushWoosh register success: " + JSON.stringify(data));
                 }, function(errorregistration) {
                     alert("Couldn't register with PushWoosh" +  errorregistration);
                 });

     }
 break;

谢谢大家,我在这里感觉自己像个白痴,度过了令人沮丧的一天。

【问题讨论】:

  • 提示:jslint.com 或 jshint.com
  • 你能给出实际的错误吗?
  • 根据 javascriptlint.com,它是“SytaxError:语法错误”。尽管我发现如果我删除了代码的特定部分,错误就会消失。让我编辑它并显示我认为的故障代码是什么。谢谢大家

标签: javascript push-notification phonegap-build


【解决方案1】:

您的onNotificationGCM() 函数未关闭,其中的开关块也未关闭。 JavaScript 解析器预计会看到两个额外的右大括号 (}),但输入文件在看到它们之前就终止了。

我的猜测是,您需要在 break; 语句之后,在分配 PushNotification.prototype.register 之前添加这两个大括号。

【讨论】:

  • 呸,我会支持你,但我没有代表。不过我会标记的。在编辑中,我将放置修复它的代码。谢谢你们,你们都很棒!
猜你喜欢
  • 2020-05-04
  • 1970-01-01
  • 2014-08-27
  • 2010-10-25
  • 1970-01-01
  • 1970-01-01
  • 2016-10-12
  • 2012-08-28
  • 1970-01-01
相关资源
最近更新 更多