8.10 The this Keyword I


#1

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?


#2

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.


#3

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.


#4

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