8.10 The this Keyword I


sayHello: function() {
return Hello, my name is ${this.name}
//return a name | works

sayHello: () => {
return Hello, my name is ${this.name}
//return undefined | does not work, why?


Binding of the this keyword, when using correct syntax this will bind to the object its defined in, else it will point the the window object.


What I could read from the MDN website is that arrow functions doesn’t have their own this. So that it’s better to use regular functions declarations for Methods.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.