如何设置jslint的选项以忽略at符号的错误或警告(@)
object:
{ name: stackoverflow
@href: http://stackoverflow/questions/ask }
console.log(object.name + "...name" + object.@href + "...href");
如果符合,我会收到Linting错误:E024:意外的'@'。
注意:@href是系统生成的;
JSON应该是这样的
{
"name": "stackoverflow",
"@href": "http: //stackoverflow/questions/ask"
}
试试这个:
console.log(object.name + "...name" + object["@href"] + "...href");
原始示例中的代码不是有效的JS,因此JSLint正确地警告您代码的合法问题。上面的更正版本是有效的,JSLint应该对上面的内容感到满意。
旁白:我假设上面代码片段的前几行只是为了说明你正在看的对象的结构?正确的JS对象文字看起来像这样:
{
name: "stackoverflow",
"@href": "http://stackoverflow/questions/ask"
}
(或者要使它成为有效的JSON,你需要将name
放在引号中)