Var T = 0
...
var TestClass = new Class()
TestClass.extend({
init: function () {
this.TT = T;
T++
}
});
TestClass.include({
animate: function () {
A = this
window.requestAnimationFrame(function () {
A.animate();
console.log(A.TT)
});
}
});
...
var can1 = new TestClass();
var can2 = new TestClass();
var can3 = new TestClass();
...
var can1.animate()
var can2.animate()
var can3.animate()
所以它只适用于can3。 控制台:>> 2
如果我愿意的话:
TestClass.include({
animate: function ()
{
console.log(this.TT)
}
});
var can1 = new TestClass();
var can2 = new TestClass();
var can3 = new TestClass();
function G() {
window.requestAnimationFrame(function () {
can1.animate()
can2.animate()
can3.animate()
G()
});
}
G()
它可以正常工作,但我如何在每个TestClass中执行requestAnimationFrame?
答案 0 :(得分:0)
我有同样的问题。所以做吧。 试试吧? https://github.com/mixed/requestAnimationFrameInterval
TestClass.include({
animate: function () {
A = this
window.requestAnimationFrameInterval(function () {
A.animate();
console.log(A.TT);
});
}
});
var can1 = new TestClass();
var can2 = new TestClass();
var can3 = new TestClass();
var can1.animate()
var can2.animate()
var can3.animate()
`