1
class ExampleClass{
   constructor(){
   }
   method1 = () =>{
       /* code
       */
   }
}

For the above code I get error

method1 = () => {`
        ^

SyntaxError: Unexpected token =

5
  • What are you trying to accomplish? Class methods can't be anonymous, how would you call them? What do you think the benefit of an arrow function is here? Commented Apr 4, 2018 at 12:53
  • More importantly, what version of Node are you using? Commented Apr 4, 2018 at 12:54
  • 2
    remove =. check Classes Commented Apr 4, 2018 at 12:57
  • node version v8.7.0 Commented Apr 4, 2018 at 13:03
  • You can do it inside the constructor, but using this.method1 = () => {} instead, but I dont know if that's the best choice. Commented Apr 4, 2018 at 13:06

1 Answer 1

2

There is no native support for class instance fields just yet. Your best option at the minute is to use a transpiler like Babel which does have support for this syntax.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.