mercredi 28 juin 2017

describe "this._sender" in Javascript Observer pattern?

Hi there great developers

I don't get it the role of this._sender in below Code.

var Event = function (sender) {
this._sender = sender;
this._listeners = [];
}

Event.prototype = {

    attach: function (listener) {
        this._listeners.push(listener);
    },

    notify: function (args) {
        for (var i = 0; i < this._listeners.length; i += 1) {
            this._listeners[i](this._sender, args);
         }
    }

};

Will someone please describe it?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire