Skip to content

Instantly share code, notes, and snippets.

@vladima
Created October 27, 2015 14:32
Show Gist options
  • Select an option

  • Save vladima/7a78ecca8273ce93ee04 to your computer and use it in GitHub Desktop.

Select an option

Save vladima/7a78ecca8273ce93ee04 to your computer and use it in GitHub Desktop.
"use strict"
class ErrorBox {
constructor(div, gate) {
this.div = div;
console.log(div); //Output some instance
gate.addEventListener(this.gateListener);
}
gateListener(e) {
console.log(this.div); //Output undefined
}
}
class Gate {
constructor() {
this.handlers = [];
}
addEventListener(handler) {
this.handlers.push(handler);
}
raise() {
for (let handler of this.handlers) {
handler();
}
}
}
let gate = new Gate();
let errorBox = new ErrorBox({}, gate);
gate.raise();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment