VSCode语法错误;预期

VSCode Syntax Error ; expected

本文关键字:预期 错误 语法 VSCode      更新时间:2023-09-26

不确定这是否真的是一个问题,正如我在过去注意到的那样,VSCode会对只适用于TypeScript的东西发出警告。我正在香草JS中创建一个对象构造函数,如下所示:

"use strict";
function Imaging(outputAttr) {
    var output = document.getElementById(outputAttr);
    var svgAttributes = {
       namespace: ['http://www.w3.org/2000/svg', 'svg'],
       attributes: { // colon here
        style: "border: 1px solid black", //d in border, b in black
        width: "200", height: "300" }, //t in width
       attributeNamespace : ['http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink']
    };
}

var svgAttributes下,我得到一个红色的歪歪扭扭,错误为"; expected"。据我所知,一切都正常,但我不确定为什么我在编辑器中出现这个错误。我是不是错过了什么?

我在评论中注意到了确切的位置。

我认为这是因为你必须在function Imaging的末尾添加一个;,如下所示:

"use strict";
function Imaging(outputAttr) {
    var output = document.getElementById(outputAttr);
    var svgAttributes = {
       namespace: ['http://www.w3.org/2000/svg', 'svg'],
       attributes: { // colon here
        style: "border: 1px solid black", //d in border, b in black
        width: "200", height: "300" }, //t in width
       attributeNamespace : ['http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink']
    };
}; // <----- just here