Michael Schwartz Michael Schwartz - 5 months ago 115
Javascript Question

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

JSLint tells me "Expected an identifier and instead saw 'class' (a reserved word)"

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


NOTE: The code runs find without any errors I'm just wondering....

What can I do to get rid of this lint from appearing while still having my function run without errors?

Full code for function...

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();

Answer

You can also disable JSLint at the file scope or at the single-line scope by using a directive in the comments. This section from the JSLint documentation seems to point to the rule that is applying. You should be able to disable it by writing something like.

/*jshint es5: false */

Hopefully this helps, and it may be more preferable than quoting your object property names.