function & closure in Javascript

 I've got this error!! 


Actually I shouldn't write function keyword in the Javascript class definition. Javascript doesn't allow function declarations as class members. The other syntax for this is, 

Method 1

myFunction(name) {
return "Hello " + name;
}

Method 2

myFunction = (name) => {
return "Hello " + name;
}


Reference:

Unexpected token. A constructor, ... was expected - error


Comments