gpt4 book ai didi

javascript - “音频”在定义之前就被使用了

转载 作者:行者123 更新时间:2023-12-02 17:16:22 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com