语法错误:意外的标记(即使行为空

SyntaxError: Unexpected token ( even when line is empty

本文关键字:错误 意外 语法      更新时间:2023-09-26

我有这个 HTML:

<template is="auto-binding" id="container-binding-template">
  <core-scaffold id="scaffold" onscroll={{containerScrolled}}>
    <div id="container">

自动绑定模板和<core-scaffold>是聚合物的一部分。

这是JavaScript:

var template = document.querySelector('#container-binding-template');
template.containerScrolled = function() {
  // regardless of the code here, the error will occur (event if it's empty)
};

当我运行此代码时,出现以下错误(在Chrome DevTools中):

未捕获的语法错误:意外令牌 ( VMxxxx:2

当我打开 VMxxxx 文件(例如 VM1362)时,我看到以下代码:

(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {function () {
    // This line contains the same code as in containerScrolled(). This is where the error is pointing to.
  }
};}}}})

导致此错误的原因是什么?我该如何解决它?任何帮助将不胜感激。

更新#1:JSFiddle

事件属性应on-scroll 。您拥有的是本机内联事件处理程序,它们期望输入是函数的主体。