谷歌浏览器中的意外令牌非法 javascript 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2157391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:59:45  来源:igfitidea点击:

Unexpected token ILLEGAL javascript error in Google Chrome

javascriptjsongoogle-chromewebkit

提问by Dustin

I am getting a javascript (prototype.js) error: Unexpected token ILLEGAL at this line of code:

我在这行代码中收到一个 javascript (prototype.js) 错误:意外令牌非法:

newFriend = new friend(
    response[0].@items[0]._id, 
    response[0].@items[0]._nickName, 
    response[0].@items[0]._profilePicture, 
    response[0].@items[0]._tagLine, 
    response[0].@items[0]._isInvite, 
    response[0].@items[0]._confirm
);

the response object looks like this:

响应对象如下所示:

[{
  "@type": "[Lcom.photoviewer.common.model.ThinUser;",
  "@items": [{
    "_id": "000.060318.05022007.00263.0067ur",
    "_nickName": "siraj",
    "_country": null,
    "_currentStorageLimit": 5000000000,
    "_currentStorage": 0,
    "_currentFileCount": 0,
    "_profilePicture": null,
    "_tagLine": null,
    "_membershipLevel": 0,
    "_isRejected": false,
    "_isInvite": false,
    "_confirm": false,
    "_verifiedOn": 1170716666000
  }]
}]

This is only happening in the Google Chrome browser and possibly other webkit browsers. It works fine in Firefox.

这仅发生在 Google Chrome 浏览器和可能的其他 webkit 浏览器中。它在 Firefox 中运行良好。

回答by Luca Matteis

Try this instead:

试试这个:

newFriend = new friend(
    response[0]["@items"][0]._id, 
    response[0]["@items"][0]._nickName, 
    response[0]["@items"][0]._profilePicture, 
    response[0]["@items"][0]._tagLine, 
    response[0]["@items"][0]._isInvite, 
    response[0]["@items"][0]._confirm
);

I'm pretty sure @is giving you a problem.

我很确定@给你带来了问题。

For weird characters it's always safer to use the ["@items"]notation instead of the (dot) notation .@items.

对于奇怪的字符,使用["@items"]符号而不是(点)符号总是更安全.@items

回答by Quentin

Property names containing @and dot notation are incompatible in Chrome. Use square bracket notationinstead (you already do when you construct the object).

包含@点符号的属性名称在 Chrome 中不兼容。改用方括号表示法(您在构造对象时已经这样做了)。