on.js (373B)
1 2 /** 3 * Module exports. 4 */ 5 6 module.exports = on; 7 8 /** 9 * Helper for subscriptions. 10 * 11 * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter` 12 * @param {String} event name 13 * @param {Function} callback 14 * @api public 15 */ 16 17 function on (obj, ev, fn) { 18 obj.on(ev, fn); 19 return { 20 destroy: function () { 21 obj.removeListener(ev, fn); 22 } 23 }; 24 }