Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MemeGenerator {
- constructor(options){
- this.options = options;
- }
- print() {
- console.log(this.options);
- }
- }
- class Meme {
- constructor(_options={}){
- this.defaultOptions={"poke": "oddish"};
- this.options = Object.assign(this.defaultOptions, _options);
- }
- MemeGenerator(_options=this.options) {
- return new MemeGenerator(_options);
- }
- }
- const meme = new Meme();
- const memeGen = meme.MemeGenerator();
- memeGen.print(); //Prints: { poke: 'oddish' }, which is the resulting options variable when options are generated, overwriting defaultOptions
- //We set some options { "doot" : "doot doot" } to be used by any classes of this Meme node module...
- const memeO = new Meme({ "doot": "doot doot" });
- //We create an instance of MemeGenerator from our Meme modules...
- const memeGenO = memeO.MemeGenerator();
- //And... this will print our combined options, without us needing to repass them! Those being: { poke: 'oddish', doot: 'doot doot' }
- memeGenO.print();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement