I’m trying to access this.collection from within a setInterval. However, this isn’t bound. I can’t seem to figure out how to bind it so that this can access the collection, not the setInterval object.
Here’s a snipit from my View.
initialize: function(){
_.bindAll(this);
},
start: function() {
setInterval(function() {
this.collection.each(function(item) {
console.log(item.id);
});
}, 5000);
}
Any suggestions?
You should
bind()the value ofthisyou need when you set up the callback:Don’t forget to include the shim from the above MDN page if you need IE8 compatibility.