I have an object as so:
let game = {
canvas: document.getElementById('main_canvas').getContext("2d"),
clear: function(){
this.canvas.clearRect(0,0,400,400);
},
update: function(){
this.clear();
//more code
},
};
In my clear method everything works using 'this' referring to 'game', however when I use 'this' in the 'update' method it doesn't refer to 'game'? When i use game.clear(); everything works, but with 'this' i get undefined. If anyone know the reason for this please post a response. I have recently learned about objects and know that arrow functions don't give a 'this', but thought anonymous functions like the ones above would allow me to refer to the 'parent' or owner object.