I have this function in Game.js
Game.prototype.onClick = function(event){
var x = event.x;
var y = event.y;
if (this.blueDeck[0].contains(x, y))
alert("Blue Deck Clicked");
}
OnClick gets called from this function in Main.js
canvas.addEventListener('mouseup', game.onClick, false);
and I have this function in Card.js
Card.prototype.contains = function(x, y){
return true;
}
The alert never comes up.
If I remove the if statement in onClick, the alert gets called.
Other functions like this.blueDeck[0].setDeckPos(w, h); work fine when called in Game.js.
Why is contains not returning true?
thisrefers to what you want it to? How/when are you calling theonClickmethod?thisprobably refers to something else (like the DOM element, which I'd assume this method is bound to) which does not have ablueDeckproperty and therefore throws an error.containsfor sure returnstrue.