每个模块有多少 类
How many classes per module
多少个classes/functions最好放到一个模块(也就是后面的require
d,f.ex. by RequireJS, the Mozilla addon loader, ...)?
由于模块似乎是批发进口的(与f.ex相反。Python,你可以这样做from module import class
),最好让它们尽可能小?还有其他准则吗?
最佳做法是什么?
(关于 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" 也有类似的问题)等,但没有出现 JavaScript-specific。)
也许这些问题已经足够老了,可以通过网站标准。现在,它对某些人来说可能真的太宽泛了。
我个人在使用 RequireJS 时做了以下操作:
- 每个模块一个 class
- 以class名字命名的模块文件
这样便于维护,并且可以动态加载所需的 classes。
唯一的缺点可能是文件的数量,但您可以使用 RequireJS 捆绑以后最常用的文件 optimization features。
多少个classes/functions最好放到一个模块(也就是后面的require
d,f.ex. by RequireJS, the Mozilla addon loader, ...)?
由于模块似乎是批发进口的(与f.ex相反。Python,你可以这样做from module import class
),最好让它们尽可能小?还有其他准则吗?
最佳做法是什么?
(关于 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" 也有类似的问题)等,但没有出现 JavaScript-specific。)
也许这些问题已经足够老了,可以通过网站标准。现在,它对某些人来说可能真的太宽泛了。
我个人在使用 RequireJS 时做了以下操作:
- 每个模块一个 class
- 以class名字命名的模块文件
这样便于维护,并且可以动态加载所需的 classes。
唯一的缺点可能是文件的数量,但您可以使用 RequireJS 捆绑以后最常用的文件 optimization features。