bind this to arrow function code example
Example 1: js arrow function this
const person = {
firstName: 'Viggo',
lastName: 'Mortensen',
fullName: function () {
return `${this.firstName} ${this.lastName}`
},
shoutName: function () {
setTimeout(() => {
console.log(this);
console.log(this.fullName())
}, 3000)
}
}
Example 2: javascript this inside arrow function
function A() {
this.val = "Error";
(function() {
this.val = "Success";
})();
}
function B() {
this.val = "Error";
(() => {
this.val = "Success";
})();
}
var a = new A();
var b = new B();
a.val
b.val