There’s plenty to happy about!
Arrow Function Expression
Note: You may see some people refer to them as fat arrow functions.
1, 2, 3 Arrow Function
You may find it helpful to break the process required to create an arrow function up into three steps:
1. Provide the parameters
2. Add in that fat arrow goodness
3. Define the body of the function
One of the key things to note is that when you only use one argument the function returns the result implicitly. You don’t have to use the return keyword. This is quite handy for lots of scenarios. Other programming languages refer to this style as lambdas.
Lexical this Binding
In ES5, you might try writing the following code:
With ES6 arrow functions, this refers to the enclosing context. So you can use:
Well, that is a quick overview of ES6 arrow functions. I hope you feel like you’ve leveled up your ES6 knowledge. You should be ready to begin taking on ES6 arrow functions.
You should spend some time practicing what you’ve learned. If you haven’t already, make sure to check out my post, You Need To Know That ES6 Has Arrived. It will get you motivated to start putting your ES6 knowledge to use now.
If you’ve found this post helpful, please make sure and leave a comment. Let me know how I’m doing. It helps me a lot.