Сделал вот так, все заработало, но осталась маленькая ошибка.
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 () {
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();
myClass.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.animate()
},
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)
},
animate: function () {
console.log("was here 1")
requestAnimationFrame(this.animate);
this.draw()
}
});
myClass.init(document.getElementById("canvas"))
браузер ругается и выдает:
Uncaught TypeError: Failed to execute 'requestAnimationFrame' on 'Window': The callback provided as parameter 1 is not a function.testClass.html:83 myClass.extend.animate