SHARE
TWEET

Untitled

a guest May 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MemeGenerator {
  2.  
  3.   constructor(options){
  4.     this.options = options;
  5.   }
  6.  
  7.   print() {
  8.     console.log(this.options);
  9.   }
  10.  
  11. }
  12.  
  13. class Meme {
  14.  
  15.   constructor(_options={}){
  16.     this.defaultOptions={"poke": "oddish"};
  17.     this.options = Object.assign(this.defaultOptions, _options);
  18.   }
  19.  
  20.   MemeGenerator(_options=this.options) {
  21.     return new MemeGenerator(_options);
  22.   }
  23.  
  24. }
  25.  
  26. const meme = new Meme();
  27. const memeGen = meme.MemeGenerator();
  28. memeGen.print(); //Prints: { poke: 'oddish' }, which is the resulting options variable when options are generated, overwriting defaultOptions
  29.  
  30. //We set some options { "doot" : "doot doot" } to be used by any classes of this Meme node module...
  31. const memeO = new Meme({ "doot": "doot doot" });
  32. //We create an instance of MemeGenerator from our Meme modules...
  33. const memeGenO = memeO.MemeGenerator();
  34. //And... this will print our combined options, without us needing to repass them! Those being: { poke: 'oddish', doot: 'doot doot' }
  35. memeGenO.print();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top