What is the difference between () => {} and function () {} in reactive javascript?

I saw some functions defined as function(){} , and some functions defined as () => {} .

Is this related to the Javascript version of ES6?

Also, how does the use of the this change from one function definition to another?

+6
source share
1 answer

() => {} is called the arrow function . They, as you said, are part of ES6. On the linked page:

An arrow function expression has a shorter syntax than a function expression and lexically binds this value (does not bind its own this , arguments , super or new.target ). The arrow functions are always anonymous.

+12
source

All Articles