//publisher class
function Observer() {
    this.subscribers = [];
};

Observer.prototype.raise = function(data) {
    this.subscribers.forEach(function(fn) { fn(data); });
};

//handle method to all existing objects
Function.prototype.handle = function(publisher) {
    var that = this;
    var alreadyExists = publisher.subscribers.some(function(el) {
        if (el === that) {
            return;
        }
    });

    if (!alreadyExists) {
        publisher.subscribers.push(this);
    }
    return this;
};
