Javascript’s “This”
When a method is called, “this” is referring to the object that is provoking the method.
For example: Here we have an object called “myperson”, and inside it is a method called “greeting”. When we run the run this code, “this”, will refer to my person.
var myperson = {
name: "Mark",
greeting: function () {
console.log("Hello my name is " + this.name)
}
}
console.log(myperson.greeting());
Therefore console log will return “Hello my name is Mark”.
Last modified: July 16, 2018
Mark Endley