My task is very simple I need two workers running.
var taskNum = 0;
function Task() {
var me = this;
this.name = '#' + ++taskNum;
Task.prototype.run = function () {
console.log(me.name);
setTimeout(me.run, 1000);
}
}
var t1 = new Task();
t1.run();
var t2 = new Task();
t2.run();
The output should be 1,2,1,2 but it is: 1 2 1 2 2 2 2 2 2
This could be solved by changing 'Task.prototype.run' to 'this.run'. But can this be fixed by not removing the prototype, because I need it in complex solution?