最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Visual Studio Code 'const' can only be used in a .ts file - Stack Overflow

programmeradmin3浏览0评论

I am getting this error while trying a write a basic JS in Visual Studio Code.

Already tried changing the settings.json ( $workspace/.vscode/settings.json ) but it doesn't work.

  {
     "javascript.validate.enable": false
  }

I am getting this error while trying a write a basic JS in Visual Studio Code.

Already tried changing the settings.json ( $workspace/.vscode/settings.json ) but it doesn't work.

  {
     "javascript.validate.enable": false
  }

Share Improve this question edited Jul 26, 2017 at 5:47 Junaid 1,3003 gold badges15 silver badges35 bronze badges asked Jul 26, 2017 at 1:50 Vinay MadanVinay Madan 1531 gold badge1 silver badge6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 12

Afaik, You can't define static const within the class declaration. you can try something like this

const MAX_WIDTH = 8.5;

class Books {
  get MAX_WIDTH() {
    return MAX_WIDTH;
  }
}

let myBooks = new Books()
alert(myBooks.MAX_WIDTH);

Are you sure it is right javascript syntax?

class Books {
    static const MAX_WIDTH = 8.5;
}

So far as i know, it's not possible to define static property even in ES2015.

You may try some way else, for example:

class Books {
    static get MAX_WIDTH() {
        return 8.5;
    }
}

console.log(Books.MAX_WIDTH);//8.5
发布评论

评论列表(0)

  1. 暂无评论