Under the following code, how do I call the function searchBlock() in the canvas click event?this.searchBlock() can't work here!
Board.prototype = {
addHandlerToBlock:function(){
this.canvas.onclick = function(e){
var e = window.event || e;
var rect = this.getBoundingClientRect();
var mouseX = e.clientX - rect.left;
var mouseY = e.clientY - rect.top;
var clickBlockId = this.searchBlock(mouseX, mouseY) || -1;
if(clickBlockId >= 0){
if(canMove(this.puzzle[clickBlockId])){
alert("ha")
}
}
this.refresh(p);
}
},
searchBlock:function(x, y){
for(var i = 0; i < this.puzzle.length; i++){
if( x - this.puzzle[i].x > 0 && y - this.puzzle[i].y > 0){
return i;
}
}
}
}
var board = new Board(); var block = board.searchBlock(x, y);