Monday, July 18, 2011

How can I pass a parameter to a setTimeout() callback?

I am getting "t is not defined" error when trying to execute the following code:

TaskList.prototype.GetTaskItems = function() {
var t = this;
%$.ajax({
...,
success: function(data) {...},
error: function() {
setTimeout("t.GetTaskItems()", 30000);
}
});
}

Not too sure why it doesn't work, but here's a workaround:
setTimeout(function() {
t.GetTaskItems();
, 30000);

No comments:

Post a Comment