I have two ways to define sayHi
method:
1. BoardMember.prototype.sayHi = ()=>{return `Hi, my name is ${this.name}. I am from ${this.homeState}, and I was trained in ${this.training}.`}
2. BoardMember.prototype.sayHi = function(){
return `Hi, my name is ${this.name}. I am from ${this.homeState}, and I was trained in ${this.training}.`
}
When I try to call someBoardMember.sayHi()
, the first one's this
refers to the global object, window
, while the second one refers to the someBoardMember
, I don't really get why. Don't they have the same receiver? What makes this
different??