How to use the Sencha ExtJS or Touch DelayedTask (example)

Here’s a quick example of how to use a Sencha ExtJS or Touch DelayedTask:

onMainViewportAfterRender: function(viewport, options) {
    var tabPanel = viewport.down('tabpanel');
    var task = new Ext.util.DelayedTask(function() {

As shown, the first thing you do is create a task by giving a DelayedTask a callback function. Then you tell the task how long it should delay before executing.

There are better reasons to do this than what I’ve shown, but (a) this is a simple example, and (b) I have been having a hard time trying to set the active tab, and as a quickie bug fix for the moment, this works.

Note that you can also do this with plain old JavaScript and setTimeout, like this:

setTimeout(myFunction, 250);