Skip to content

Instantly share code, notes, and snippets.

@ryanneufeld
Created October 11, 2012 21:36
Show Gist options
  • Save ryanneufeld/3875639 to your computer and use it in GitHub Desktop.
Save ryanneufeld/3875639 to your computer and use it in GitHub Desktop.
Array prototype example
/**
* This script will process a queue of events. The event queue can be built up before
*
* http://cl.ly/image/1b001E3b1c0A
*
*/
var _mlq = _mlq || [];
function mlQueue(_q, name) {
function _Q() {}
_Q.prototype = [];
_Q.name = name || 'Fifo Queue';
_Q.prototype._init = function() {
this.processQueue();
}
_Q.prototype.processQueue = function() {
var that = null;
while (this.length > 0) {
task = this.shift();
if (task.length) {
func = task.shift();
if (typeof func === 'function') {
func.apply(window, task);
}
}
}
}
_Q.prototype._push = _Q.prototype.push; // re-assigning it.
_Q.prototype.push = function() {
this._push.apply(this, arguments);
this.processQueue();
}
var q = new _Q();
q.push.apply(q, _q);
q._init();
return q;
}
//Initialize the queue now.
_mlq = new mlQueue(_mlq, 'Page Queue');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment