Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Last active January 4, 2016 20:59
Show Gist options
  • Save bendrucker/8677371 to your computer and use it in GitHub Desktop.
Save bendrucker/8677371 to your computer and use it in GitHub Desktop.
define(['EventEmitter', 'bluebird'], function (EventEmitter, Promise) {
'use strict';
EventEmitter.prototype.emitThen = function (event) {
var args = Array.prototype.slice(arguments, 1);
return Promise
.bind(this)
.thenReturn(this._events[event] || [])
.map(function (handler) {
return handler.apply(handler.context || this, args);
})
.thenReturn(null);
};
return EventEmitter;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment