I’m trying to call a method of all button objects on every mouse click, but I’m not at all familiar with how javascript prototypes work, would greatly appreciate some help. Here’s what I have so far.
var button1 = new button(200, 200, 150, 150, "testFunc();");
function button(x,y,width,height, func) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.func = func;
}
button.prototype.click = function(clickx, clicky) {
eval(this.func)
console.log("Clicked button at" + this.x + " " + clicky);
if (clickx > this.x && (clickx + width) < this.x) {
if (clicky > this.y && (clicky + height) < this.y) {
this.func(); //Call the button's function
}
}
}
function onClick(x, y) {
button.prototype.click.call(x, y);
}
I basically want every button object to check if it was clicked using the xy coordinates of the click. Certainly this should be possible with javascript?
Ok, a few things.
Buttonnotbutton.evalfor anything.