i want to add event handler to object's class (with JQUERY), but i cannot find solution to my problem. I have code like this:
class Obstacle
{
constructor()
{
this.points = [];
}
}
class Editor
{
constructor()
{
this.obstacle = new Obstacle;
}
addPoint()
{
this.obstacle.points.push(canvas.click( function(e) { return [e.clientX, e.clientY]; }));
alert(this.obstacle.points.length);
}
}
Of course without any results, so i'm asking for any help :).
clickmethod, as an argument, is called from the event queue (or in this particular case, inside jQuery). What is pushed to the array is the return value of.clickcall, and that's done only once, when you've calledaddPoint(). You've to push the coordinates to the array inside the event handler function.canvas.click(function(e) { this.obstacle.points.push([e.clientX, e.clientY])}), but error occured that push method was not defined