-1

How many classes/functions are best put into a module (which is later required, f.ex. by RequireJS, the Mozilla addon loader, ...)?

As the module seems to be imported wholesale (contrary to f.ex. Python, where you can do from module import class), would it be best to keep them as small as possible? Any other guidelines?

What is the best practice?

(There are similar questions about Java (which recommends "the more granular class layout you have, the better"), Python (which allows for more objects and states "Python is not C#/Java. Trying to bend it to make it look like $other_language will cause frustration and poor user experience") , etc, but nothing JavaScript-specific appeared.)


Maybe these questions were old enough to pass the site standards then. Nowadays, it might be really too broad for some.

Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • As is, this question is too broad. A complete answer would be well too long for the Stackoverflow format. – Magisch Feb 05 '16 at 08:37
  • Recommendations for off-site ressources are off topic on Stackoverflow. I don't think this question is a good fit for Stack Overflow as a site. – Magisch Feb 05 '16 at 08:39
  • 1
    @Magisch: @ Arnaud has answered this, so it should not be too broad. Similarly, the Python, Java, ... questions have usual-length answers, too. – serv-inc Feb 05 '16 at 08:44
  • 1
    as many as it needs and not a single line more. – dandavis Feb 05 '16 at 08:45
  • 1
    Agreed with user, this is a legitimate question when using RequireJS, and is not too broad since it accepts a concise answer. The answer is taken from my personal experience of RequireJS during several years. – Arnaud Weil Feb 05 '16 at 09:18

1 Answers1

0

I personally do the following when using RequireJS:

  • One class per module
  • Module file named after the class name

This allows for easy maintenance, plus dynamic loading of the needed classes.

Only drawback could be the amount of files, but you can bundle the ones most used later using RequireJS optimization features.

Arnaud Weil
  • 2,324
  • 20
  • 19