1

I have been working alongside my boss on a new site. He uses Visual Studio 2013, I use Visual Studio 2015. For some reason, the Javascript "class" keyword displays as an error on his copy of Visual Studio, but displays fine on my side:

Error on my boss's VS2013 instance

This shouldn't break the site, but it seems to mess with 2013 by displaying what's in the screenshot above.

Why does this happen on VS2013? To reiterate - it doesn't happen on my 2015 edition.

Eon
  • 3,833
  • 10
  • 46
  • 75
  • What does the Error List Window report? – thgaskell Dec 05 '16 at 09:20
  • Simple answer: VS2013 does not suppor the class keyword. The older specification of javascript, ES3 (ES 1999) reserved the "class" keyword so using the class keyword is considered an error. The ES6 spec finally specified the class keyword so it's no longer an error but a proper keyword. – slebetman Dec 05 '16 at 09:21

2 Answers2

2

The class keyword is a new edition to JavaScript. It was only standardised in ES6 from June 2015.

VS 2013 is simply too old to support it (as, for that matter, is Internet Explorer 11).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Not quite. Almost correct. The **class** keyword was standardised as early as 1999 but it was standardised as a reserved word. Using it is considered an error by some browsers (IE?) and indeed when ES5 introduced strict mode it triggers an error in strict mode. ES6 finally makes it a feature thus using it is no longer an error. – slebetman Dec 05 '16 at 09:22
  • @slebetman — Reserved or not, it would have been an error placed where it was placed before it had a defined meaning. That makes no difference. – Quentin Dec 05 '16 at 09:45
2

Visual Studio 2013 simply does not support more recent versions of EcmaScript. Remember that Visual Studio 2013 is almost four years old, and the current definition of the class keyword is in EcmaScript 2015, which was suggested after Visual Studio 2013 was released. Before EcmaScript 2015, the class keyword was reserved but considered a syntax error, so Visual Studio is actually doing the right thing by marking it as an error.

Here is some more information that might help you get EcmaScript 6 support in Visual Studio 2013:

Also, if your boss is not debugging the JavaScript code using Visual Studio (or writing any), they can simply turn off JavaScript syntax checking.

Community
  • 1
  • 1
Anders Marzi Tornblad
  • 18,896
  • 9
  • 51
  • 66
  • That's what I thought. I just had to confirm for myself that this was the case. I had explained it like this to my boss. seems we are doing away with classes :( and replacing them with plain old functions. But - the more you know :) – Eon Dec 05 '16 at 09:27
  • No, don't do away with classes!! Work towards the future, and transpile to older JavaScript as long as you have to. Then, when browsers catch up, get rid of the transpiler. – Anders Marzi Tornblad Dec 05 '16 at 09:29