A normal function (function(img) {}) creates its own this, so this.canvas is undefined. And arrow functions ((img) => {}) don’t have their own this, they use this from the surrounding code. Switch to an arrow function, it will fix the problem, also, if you use use this.canvas?.add(img1) you'll avoid errors if canvas is not set yet.