Observer = Class.create({
initialize: function() {
this.callbacks = [];
},
prependCallback = function(callback) {
this.callbacks.unshift(callback);
},
appendCallback = function(callback) {
this.callbacks.push(callback);
},
runCallbacks = function() {
this.callbacks.each(
function(callback) {
callback();
}
);
}
});
bunchOfCallbacks = new Observer();
bunchOfCallbacks.appendCallback(function(){alert('second');});
$('anything').observe('anyEvent', bunchOfCallbacks.runCallbacks);
bunchOfCallbacks.prependCallback(function(){alert('first');});