javascript “this” keyword not referring to correct thing
问题 var ball = { x: 20, y: 500, vx: 100, vy: 100, width: 13, height: 13, draw: function() { var img = new Image(); img.src = 'images/ball.png'; img.onload = function(){ ctx.drawImage(img, this.x, this.y); }; }, I want the drawImage() line of code to refer to the ball.x and ball.y. Instead of using ball.x and ball.y, I want to use "this" keyword so that i can turn the ball object into a function that is a mass constructor/prototype if i end up wanting to (able to make ball1, ball2, ball3 etc.). I