Arrow Functions and this

Cara lama :

const person = {
    talk() {
        var self = this;
        setTimeout(function() {
            console.log("self", self);
        }, 1000);
    }
}

person.talk();

Cara Arrow function this :

const person = {
    talk() {
        var self = this;
        setTimeout( () => {
            console.log("self", self);
        }, 1000);
    }
}

person.talk();

Last updated

Was this helpful?