Created
August 12, 2016 10:02
-
-
Save raduGaspar/4324037c04ed747398a040aeb00079dc to your computer and use it in GitHub Desktop.
This file contains 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
let EventDispatcher = (function() { | |
let instance = null; | |
class EventDispatcher { | |
constructor() { | |
if(!instance) { | |
instance = this; | |
} | |
return instance; | |
} | |
} | |
return EventDispatcher; | |
}()); | |
class Keyboard extends EventDispatcher { | |
constructor() { | |
super(); | |
} | |
} | |
class PlayerController extends Keyboard { | |
constructor() { | |
super(); | |
} | |
} | |
class PlayerModel extends EventDispatcher { | |
constructor() { | |
super(); | |
} | |
} | |
var playerModel = new PlayerModel(); | |
var playerCtrl = new PlayerController(); | |
console.log('instanceof playerCtrl', playerCtrl); // incorrect/overwritten instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment