Skip to content

Instantly share code, notes, and snippets.

@jgermade
Last active August 29, 2015 14:08
Show Gist options
  • Save jgermade/88ff8012ad0384c7ede3 to your computer and use it in GitHub Desktop.
Save jgermade/88ff8012ad0384c7ede3 to your computer and use it in GitHub Desktop.
function _Emitter (name) {
this.callers = {};
}
_Emitter.prototype.add = function () {
this.callers[this.name] = true;
};
_Emitter.prototype.log = function () {
console.log(JSON.stringify(this.callers));
};
// inherited
function Emitter (name) {
this.name = name;
}
Emitter.prototype = new _Emitter();
// tests
var common = new Emitter(),
foo = new Emitter('foo'),
bar = new Emitter('bar');
foo.add();
bar.add();
common.log();
//
// Recource.on('update', '087td08d7t0d78td073y3y893y', function () {});
//
// Recource.on('update', 'any', function () {});
//
@jgermade
Copy link
Author

console output:

"{"foo":true,"bar":true}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment