【发布时间】:2013-05-14 22:54:14
【问题描述】:
我有一个 app-object 构造函数,如下所示:
var app = function(loadedsettings) {
return {
init: function() {
this.loop();
},
loop: function() {
this.update();
window.requestAnimationFrame(this.loop);
},
update: function() {
//loop through settings and call update on every object.
},
settings: [
//array of settings objects, all with update methods.
]
};
}
然后当我这样做时:
var theApp = app(settings);
theApp.init();
我明白了:
Uncaught TypeError: Object [object global] has no method 'update'
因为在调用requestAnimationFrame时,循环函数内部的this-value被设置为window。
有人知道如何调用 requestAnimatinFrame 并将 'theApp' 对象设置为 this 值吗?
【问题讨论】:
标签: javascript html5-canvas requestanimationframe