JSLint:期望一个标识符,却看到了'class'(保留词)

JSLint: Expected an identifier and instead saw 'class' (a reserved word)

本文关键字:保留 class 期望 一个 JSLint 标识符      更新时间:2023-09-26

JSLint告诉我"期望一个标识符,而不是看到'class'(一个保留字)"

$("<a/>", {
  class: "fr" // Error appears here
}).attr("data-name", f)

注意:代码运行发现没有任何错误,我只是想知道....

我能做些什么来摆脱这个lint从出现,同时仍然有我的函数运行没有错误?

函数的完整代码…

var showFiles = function() {
  listFiles.forEach(function(f) {
    $("[data-action=filetree]").append(
      $("<div/>").append(
        $("<a/>", {
          text: f
        }).attr("data-name", f)
        .attr("data-nme", f)
        .attr("data-location", "file://" + __dirname + "/content/project/" + f),
        $("<a/>", {
          class: "fr"
        }).attr("data-name", f)
        .html("<i class='"fa fa-times'"></i>")
        .attr("data-delete", "file://" + __dirname + "/content/project/" + f)
      )
    );
  });
};
showFiles();

你也可以通过在注释中使用一个指令来禁用JSLint在文件范围或单行范围。JSLint文档中的这一节似乎指向了正在应用的规则。您应该能够通过写入。

来禁用它。
/*jshint es5: false */

希望这有帮助,它可能比引用对象属性名更可取。