T
T
Torento203452021-04-19 13:55:23
JavaScript
Torento20345, 2021-04-19 13:55:23

Why does babel swear at this class syntax?

Why babel swears at a line test = null;
In the browser, such an entry works and does not give errors, but babel does not approve.
Recording static test = null;is also not acceptable.

class Test {
  test = null;
  showTest() {
    console.log(this.test);
  }
}

What is the correct way to write a property?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-04-19
@Torento20345

Try adding to babel.config.js

module.exports = {
  plugins:  [
    '@babel/plugin-proposal-class-properties'
  ]
}

Well, install, of course, this package

A
Alexander, 2021-04-19
@Aleksandr-JS-Developer

Write properties through a methodconstructor()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question