我有这个 HTML:
<template is="auto-binding" id="container-binding-template">
<core-scaffold id="scaffold" onscroll={{containerScrolled}}>
<div id="container">
自动绑定(bind)模板和<core-scaffold>
属于 Polymer 的一部分.
这是 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 中):
Uncaught SyntaxError: Unexpected token ( 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
。您拥有的是 native 内联事件处理程序,它期望输入是函数的主体。
关于javascript - 语法错误: Unexpected token ( even when line is empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27092250/