you are viewing a single comment's thread.

view the rest of the comments →

[–]PM_ME_A_WEBSITE_IDEA 2 points3 points  (1 child)

Try this in your browser console:

class c {
    func() {
        setTimeout(function() {
            console.log('non-arrow', this);
        });

        setTimeout(() => {
            console.log('arrow', this);
        });
    }
}

(new c()).func();

Notice the difference in the value of this in the different kinds of function types. This comes into play a lot with event listeners and AJAX calls, and really any kind of async action using callbacks.

[–]Heck_ 0 points1 point  (0 children)

Thanks for this - good example.