Thread.Simple.prototype = $.extend({}, Thread.prototype); $.extend(Thread.Simple.prototype, { addTask: function(item) { this._data.push(item); return this; }, _tasks: 0, _numTasks: 0, run: function() { var data = this._data.pop(); if (data) this._run(data); else return true; // All tasks completed // Complete a task if (this._tasks < this._numTasks) { this._tasks++; // We can run more tasks per "thread call"; may be slow on large data sets // due to recursive functions behavior in JavaScript. return this.run(); } this._tasks = 0; return false; } });