Created
October 27, 2015 14:32
-
-
Save vladima/7a78ecca8273ce93ee04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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