If you want to have the this
property be consistent, you should bind the functions that are being called.
For example,
setInterval(function() { /* code here */ }.bind(this), 500)
That way, the this
of the inner function will be the same as that of the outer function.