W
W
webe2018-06-27 03:48:12
React
webe, 2018-06-27 03:48:12

What is the difference between the description of methods in classes?

Can you tell me what's the difference?
How will this stuff behave in ES6 AND ES7/NEXT
func1 and func2 have automatic this binding under the hood and will always be bound to Todo? is it a portotype or not?
func3 doesn't have any magic binding, it's a class prototype.
Did I understand everything correctly and are there any other differences?

class Todo extends Component {
state = {};

  const func0= (id) => {
return 1+1;
  };

  func1= (id) => {
  };
 
const func2= ({ username }) => <p>The logged in user is: {username}</p>;
  func3() {
  return 1;
  }	
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-06-27
@webe

You can see what your code turns into in babel repl (do not forget to check the react box in the left menu)
you cannot write const inside the class
func1 will have this referring to Todo
func3 - will not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question