botfactoryit / terremotibot

🎯 TerremotiBot 2.0 - Telegram bot
https://terremotibot.it
MIT License
20 stars 2 forks source link

Wrap classes with factory functions #1

Open matteocontrini opened 7 years ago

matteocontrini commented 7 years ago

Instead of

class Card() {
  constructor() {},
  method() {},
  _private() {}
}

we should be doing

module.exports = function cardFactory() {
  // constructor code
  let private = () => {};
  return {
    method: function method() {}
  };
};
matteocontrini commented 7 years ago

Or better: use classes but export a function that creates a new instance of the class.

class Card() {}

module.exports = function(options) {
    return new Card(options);
});