Classic and arrow functions in Javascript have a few differences. Arguably, the most impactful is their relationship to thethis
property.
For a classic function, this
refers to the function’s execution context or what can also be thought of as the object that is calling the function. In the example below, a classic function is called by the obj
object. Therefore, its this
is obj
.
const obj= {
name: "Eli",
test: function () {
console.log(this, this.name)
}
}
obj.test() // {name: "Eli", test: ƒ} "Eli"
#coding #software-development #javascript #software-engineering #programming