我有一个 JavaScript 文件,正在使用 JSLint(Notepad++ 插件 v0.8.2)检查。我设置了以下选项:
/*jslint indent: 4, maxerr: 9999, white: true, browser: true, devel: true,
es5: true, plusplus: true, regexp: true, sloppy: true */
JSLint 在这一行提示:
new Audio('sounds/ding.wav').play();
'
Audio
' was used before it was defined
好像不喜欢ES5?我怎样才能让这个错误消失?
最佳答案
您应该能够在插件选项中将音频
列为“预定义”,或者如您提到的as a global
在使用它的文件中:
/*global Audio: false */
这里包含 false
将其描述为只读。
该错误是因为 JSLint doesn't currently acknowledge it作为浏览器可能的全局变量:
// browser contains a set of global names that are commonly provided by a
// web browser environment.
browser = array_to_object([
'clearInterval', 'clearTimeout', 'document', 'event', 'FormData',
'frames', 'history', 'Image', 'localStorage', 'location', 'name',
'navigator', 'Option', 'parent', 'screen', 'sessionStorage',
'setInterval', 'setTimeout', 'Storage', 'window', 'XMLHttpRequest'
], false),
另外,请注意音频
是defined by HTML而不是 ECMAScript。
关于javascript - “音频”在定义之前就被使用了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24420493/