Skip to content

Instantly share code, notes, and snippets.

@raduGaspar
Created August 12, 2016 10:02
Show Gist options
  • Save raduGaspar/4324037c04ed747398a040aeb00079dc to your computer and use it in GitHub Desktop.
Save raduGaspar/4324037c04ed747398a040aeb00079dc to your computer and use it in GitHub Desktop.
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