javascript - Chrome 扩展程序 : Uncaught SyntaxError: Unexpected token return

标签 javascript node.js google-chrome google-chrome-extension

我在运行 Chrome 扩展时遇到的错误如下:

未捕获的语法错误:意外的 token 返回engine.js:295

这里是第 293 到 295 行,因此更容易调试:

for (var i = 0; i < document.head.childNodes.length; i++)
            if (tryReplace(document.head.childNodes[i])
                            return 

我没有正确返回吗?解决办法是什么?

最佳答案

第二行括号的顺序不正确:

function someFunc() {
  for (var i = 0; i < document.head.childNodes.length; i++)
    // Inserted missing parentheses at the end of the expression.
    if (tryReplace(document.head.childNodes[i]))
      return
}

return 语句只能在函数上下文中使用。

关于javascript - Chrome 扩展程序 : Uncaught SyntaxError: Unexpected token return,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35256431/

相关文章:

javascript - 将值从一个函数移动到另一个函数

javascript - 如何让我的图像在 HTML 或 CSS 中的某个点停止重复?

javascript - react native : change style of ListView item on touch

node.js - 不支持的投影选项 : $concat On Azure CosmosDb

python - 如何使用 Python 从 Chrome 扩展的 LocalStorage 获取数据?

javascript - D3 旋转文本 : smoothing in Chrome?

google-chrome - Firefox、Chrome、Safari 对于 MP4 HTML5 视频有灰色背景

javascript - 禁用跨域ajax请求

node.js - 如何将 S3 扩展到每秒数千个请求?

javascript - 如何开始使用 WebTorrent?