JSFiddle - React, Tailwind, and code Playground
JavaScript
function Car() {
var self = this; //locally assign this that can be closed over
self.speed = 0;
setInterval(function goFaster() {
//this has a different scope, but we can use the self variable to reference the parent "this"
self.speed += 5;
console.log('now going: ' + self.speed);
}, 1000);
}
var car = new Car();