I would avoid this keyword, because it is easy mess up things
letdog={name:"Doug",breed:"pug",sayName:function(){return"The name of this dog is "+this.name+"."}}letsayName=dog.sayNamesayName()// "The name of this dog is 0.8151551794824166."// To make it work you needsayName.call(dog)// or sayName.apply(dog)
instead you can, for example, use closures:
constcreateDog=()=>{constself={name:"Doug",breed:"pug",sayName:()=>`The name of this dog is ${self.name}.`}returnself}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I would avoid
this
keyword, because it is easy mess up thingsinstead you can, for example, use closures: