Skip to content

Extending Tasks

Eric McGary edited this page Jan 6, 2013 · 4 revisions

In some cases you may have a need for more specific functionality then what is provided with the simple, parallel and sequence task types. It is very simple to extend the base functionality of a specific task type to bake your own.
    var MyCustomGroupTask = MonkeyBars.TaskGroup.extend({
        type:"MyCustomGroupTask",
        start:function(){
            this.customFunction();
            MonkeyBars.TaskGroup.prototype.start.call(this);
        },
        customFunction:function(){
            // custom logic
        }
    });

    var group = new MyCustomTaskGroup({
        name:"group",
        tasks:[...]
    });

    group.start(); 

An extended task contains all of the funtiaonlity available to any of the predefined task types (Simple, Parallel and Sequence). So it is possible to extend and extended task for more complex processes. The followin illustrates this...

    var AbstractTask = MonkeyBars.Task.extend({
        ...,
        performTask:function(){
            runMethod();
            this.complete();
        },
        ...
    });

    var ConcreteTaskA = AbstractTask.extend({
        ...,
        runMethod:function(){
            ...
        },
        ...
    });

    var ConcreteTaskB = AbstractTask.extend({
        ...,
        runMethod:function(){
            ...
        },
        ...
    });

Clone this wiki locally