ES6 this keyword
WIth ES6 the this keyword also change at last not the this keyword himself but when use with arrow function let's see that.
This keyword
const box6 = {
color: 'yellow',
position: 2,
lexicalThis: function() {
return this.color; // yellow
() => this.position; // 2 !!!
}
}
- In es5 to access with
thisto a property in a regular function you have to call,bindthisfor that works. - Unlike a regular function, an arrow function does not bind
this, insteadthisis bound lexycally. - In our example we create an object:
box6we give two properties and one method and like our first example in our method we can usethisto access properties of our current object, but this time instead of create an anonymous function with es5 we create an arrow function and becausethisis bound lexically you can use it like you did before and it's works.
Current errors
This is a list of the main errors that you can meet:
Note: I'm not a wizard there is maybe some issue that you notice above so fell free to open an issue in the github repo if you find a new error not mentioned above.