Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap classes with factory functions #1

Open
matteocontrini opened this issue Jan 4, 2017 · 1 comment
Open

Wrap classes with factory functions #1

matteocontrini opened this issue Jan 4, 2017 · 1 comment

Comments

@matteocontrini
Copy link
Member

Instead of

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

we should be doing

module.exports = function cardFactory() {
  // constructor code
  let private = () => {};
  return {
    method: function method() {}
  };
};
@matteocontrini matteocontrini changed the title Use factory functions instead of classes Wrap classes with factory functions Feb 11, 2017
@matteocontrini
Copy link
Member Author

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant