简体   繁体   English

第一个对象的“意外标识符”错误(仅限Safari)

[英]“Unexpected identifier” error for first object (Safari only)

When I run the following code in Safari (and only Safari), the Javascript won't load in the browser: 当我在Safari中运行以下代码(并且只有Safari)时,Javascript将不会在浏览器中加载:

$(document).ready(function() {
  let dataX = {
    last: 100
  };
  let quotes = [{
    quote: "I find it fascinating that... 

and I get an error message: SyntaxError: Unexpected identifier 'dataX' 我收到一条错误消息: SyntaxError: Unexpected identifier 'dataX'

When I comment out the dataX object, the next object creates the same error: SyntaxError: Unexpected identifier 'quotes' It seems that no matter what the first object is, it will throw an error in Safari. 当我注释掉dataX对象时,下一个对象会产生相同的错误: SyntaxError: Unexpected identifier 'quotes'似乎无论第一个对象是什么,它都会在Safari中引发错误。

The page displays a random quote in a simple Bootstrap container. 该页面在一个简单的Bootstrap容器中显示随机引用。 You can find a link to the CodePen here . 您可以在此处找到CodePen的链接。

What I've tried so far: 到目前为止我尝试过的:

  • Check the inspector and Google the error message 检查检查员和Google错误消息
  • Load the CodePen in Chrome and Firefox (it works) 在Chrome和Firefox中加载CodePen(可行)
  • Validate the HTML, and use a linter for the JS 验证HTML,并为JS使用linter
  • Open the index.html locally in Safari, with the proper <header> and <meta> tags, as well necessary Bootstrap and jQuery files. 在Safari中本地打开index.html ,使用正确的<header><meta>标记,以及必要的Bootstrap和jQuery文件。
  • Google the issue both in and beyond Stack Overflow Google Stack Overflow内外的问题
  • Comment out different functions and objects to see if it makes the page work 注释掉不同的函数和对象,看它是否使页面工作

I suspect that the problem is not the object to which the error message refers; 我怀疑问题不是错误消息所指的对象; I also suspect the solution may be trivial. 我也怀疑解决方案可能是微不足道的。 However, I am completely stumped. 但是,我完全难过了。 Any leads would be greatly appreciated. 任何线索将不胜感激。

let keyword is not supported in safari version less than 10 在小于10的safari版本中支持let关键字

so, forget using it for IOS safari 所以,忘了将它用于IOS safari

see: can I use - let 看:我可以用 - 让

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM