【发布时间】:2015-10-14 17:07:28
【问题描述】:
我正在使用 google 的闭包编译器,在构建时遇到以下错误:
path/to/file.js:...: WARNING - actual parameter 1 of Element.prototype.scrollIntoView does not match formal parameter
found : {behavior: string, block: string}
required: (boolean|undefined)
target.scrollIntoView({'block': 'start', 'behavior': 'smooth'});
^
显然,这里的target 是Element。
好的,看起来闭包想要一个布尔值,但 mdn 似乎认为an object is a perfectly fine argument。 MDN 引用 https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview 的定义是一致的(并且平滑滚动实际上在 Firefox 中有效)。
看起来 Closure 在 w3c_css.js 中定义了 extern,它在评论中引用了 http://www.w3.org/TR/cssom-view/#dom-element-scrollintoview。但是,看起来他们甚至没有正确的定义,因为 w3.org 在签名中有 2 个(可选)参数,而闭包似乎只允许传递 1。
平滑滚动是一个不错的选择(我可能会在某个时候用更好的跨浏览器解决方案替换这段代码),但与此同时,我如何消除该警告?
【问题讨论】:
-
这个错误似乎已在更新版本的编译器中得到修复。
标签: javascript google-closure-compiler