Consider:
class Welcome{
static name="something"; // Throws an error
}
MDN says static
will be supported from Chrome 42. But it is throwing a syntax error in Chrome 70 and below versions.
Consider:
class Welcome{
static name="something"; // Throws an error
}
MDN says static
will be supported from Chrome 42. But it is throwing a syntax error in Chrome 70 and below versions.
2
Answers
To fix this, you can use a transpiler like Babel.
Transpilers convert code written in newer versions of JavaScript into an older, more widely supported syntax.
MDN Web Docs does not paint a detailed picture here, as this article deals with static class methods, static blocks and static class fields. Support for these different uses of
static
did not all come in Chrome version 42. The support for static class fields came later. On the MDN Web Docs page dedicated to Public class fields it mentions Chrome version 72:If a browser doesn’t have support for static class fields, you can use this code instead: