delegate

Creates delegate functions automatically.

delegate

Creates delegate functions automatically. This is useful if you don't want to use util.inherits.

var A = function() {
  this.evtEmitter = new delegate.EventEmitter();
  delegate(this, this.evtEmitter);
};
 
var obj = new A();
obj.on("test", function (data) {
  // read data 
});
var delegate = require('delegate');
var Class = require('class.js');
 
var MyEventEmitter = function () {
  events.EventEmitter.call(this);
};
util.inherits(MyEventEmitter, events.EventEmitter);
 
var A = Class({
  initfunction () {
    this.evtEmitter = new MyEventEmitter();
    delegate(this, this.evtEmitter);
  }
});
 
var B = A.extend({
  emitDataEventfunction () {
    this.emit("data", 'hello world');
  }
});
 
var obj = new B();
obj.on("test", function (data) {
  // read data 
});

Creates delegate functions for each function found on srcObj on destObj.

Arguments

  • destObj - The object you want the delegate function to exist on.
  • srcObj - The object you want to create delegate functions to.

Convenience class the implements events.EventEmitter that you can delegate to.