Так, во избежание недопониманий, вот что имеем:
var CanvasControl = new Class();
CanvasControl.extend({
init: function (canvas_element) {
this.canvas = canvas_element;
this.canvas.width = canvas_element.offsetWidth;
this.canvas.height = canvas_element.offsetHeight;
this.ctx = this.canvas.getContext("2d");
this.WIDTH = window.innerWidth;
this.HEIGHT = window.innerHeight;
this.canvas.onmousemove = this.myMove;
console.log(this) //ВЫВОД 1
}
});
CanvasControl.include({
/*ClearStyle: function () {
this.ctx.strokeStyle = "rgba(0,0,0,1)";
this.ctx.fillStyle = "rgba(0,0,0,1)";
this.ctx.lineWidth = 1;
},
RECT: function (x, y, w, h) {
this.ctx.beginPath();
this.ctx.rect(x, y, w, h);
this.ctx.fill();
this.ctx.stroke();
},
DrawText: function (s, x, y) {
this.ctx.textBaseline = "middle";
this.ctx.textAlign = "center";
this.ctx.strokeText(s, x, y);
},
draw: function () {
this.RECT(0, 0, 100, 100);
},*/
myMove: function (e) {
console.log(this) //ВЫВОД 2
}
});
var can1 = new CanvasControl(document.getElementById("canvasA"));
Вывод 1: _class {canvas: canvas#canvasA, ctx: CanvasRenderingContext2D, WIDTH: 1920, HEIGHT: 602, ClearStyle: function…}HEIGHT: 602WIDTH: 1920canvas: canvas#canvasActx: CanvasRenderingContext2D__proto__: _class
Вывод 2: <canvas id="canvasA" width="300" height="150">
testClass2.html:91 <canvas id="canvasA" width="300" height="150">
Вопрос - как обратиться к объекту из
Вывод 1 внутри myMove