Configuración correcta de este valor en requestAnimationFrame
Tengo un constructor de objetos de aplicación que se ve así:
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.
]
};
}
Entonces cuando hago:
var theApp = app(settings);
theApp.init();
Yo obtengo:
Uncaught TypeError: Object [object global] has no method 'update'
porque cuando se llama a requestAnimationFrame, el valor de este dentro de la función de bucle se establece en ventana.
¿Alguien sabe cómo llamar a requestAnimatinFrame con el objeto 'theApp' establecido como el valor de este?