Created
July 28, 2016 18:10
-
-
Save bgergo/5e383805cb4fd58c0e0fb09bbcd21320 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
export default class AbstractAnimal { | |
constructor(ModelClass) { | |
if (!ModelClass) { | |
throw new Error('Model is required to get the config obj'); | |
} | |
this.config = { | |
type: '', | |
noise: '' | |
}; | |
Object.assign(this.config, ModelClass.prototype.config); | |
this.ModelClass = ModelClass; | |
} | |
say() { | |
if (!this.config.noise) | |
throw new Error("No one knows this sound"); | |
return this.config.noise; | |
} | |
sleepySay() { | |
return new Promise((resolve, reject) => { | |
if (!this.config.noise) | |
throw new Error("No one knows this sound"); | |
resolve(this.config.noise); | |
}); | |
} | |
} |
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
import AbstractAnimal from './AbstractAnimal'; | |
export class DogModel { | |
constructor () { | |
this.config = { | |
type: 'dog', | |
noise: 'woof' | |
} | |
} | |
} | |
export default class Dog extends AbstractAnimal { | |
constructor() { | |
super(DogModel); | |
Object.assign(this, DogModel.prototype.config) | |
} | |
say() { | |
return super.say(); | |
} | |
sleepySay() { | |
return super.sleepySay(); | |
} | |
} |
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
import AbstractAnimal from './AbstractAnimal'; | |
export class FoxModel { | |
constructor () { | |
this.config = { | |
type: 'fox', | |
noise: null | |
} | |
} | |
} | |
export default class Fox extends AbstractAnimal { | |
constructor() { | |
super(FoxModel); | |
Object.assign(this, FoxModel.prototype.config) | |
} | |
say() { | |
super.say(); | |
} | |
sleepySay() { | |
return super.sleepySay(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment