Создал собственный класс для элемента Canvas, но не работает, а ошибку найти не могу.
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery.js" type="text/javascript"></script>
<title>Canvas Drag and Drop Test</title>
</head>
<body id="menu">
<canvas id="canvas"></canvas>
</body>
<script>
console.clear();
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (function () {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback, element) {
window.setTimeout(callback, 16.7);
};
})();
}
var Class = 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;
var _class = function () { };
_class.fn = _class.prototype;
_class.extend = function (prop) {
for (var i in prop) {
_class[i] = prop[i];
}
};
_class.include = function (prop) {
for (var i in prop) {
_class.fn[i] = prop[i];
}
};
return _class;
};
var myClass = new Class(document.getElementById("canvas"));
myClass.extend({
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, this.canvas.width, this.canvas.height)
},
animate: function () {
requestAnimationFrame(this.animate);
this.draw()
}
});
</script>
</html>
Что в нем не так?