[英]TypeScript - Use PascalCasing or camelCasing for module names?
I'm wondering if I should use PascalCasing
or camelCasing
for my modules names, so far I've always used PascalCasing, ie: Ayolan.Engine.Rendering
instead of Ayolan.engine.rendering
(I keep PascalCasing for the container, since I want the global object name to be Ayolan
and not ayolan
). 我想知道我是否应该使用
PascalCasing
或camelCasing
作为我的模块名称,到目前为止我一直使用PascalCasing,即: Ayolan.Engine.Rendering
而不是Ayolan.engine.rendering
(我保留PascalCasing用于容器,因为我想要全球对象名称是Ayolan
而不是ayolan
)。
I haven't found any headline on this, found that thread from 3 years ago but not really useful. 我没有找到任何标题,发现3年前的线程 ,但没有真正有用。
I'm wondering because I'm working with Java developpers and to them it makes more sense to use camelCasing
, but that's not what I've seen so far with TS. 我想知道因为我正在使用Java开发人员而且对他们来说使用
camelCasing
更有意义,但这不是我迄今为止用TS看到的。
In TypeScript, we use the same standards as JavaScript, because we are working with many JavaScript libraries (and potentially being consumed by JavaScript code too). 在TypeScript中,我们使用与JavaScript相同的标准,因为我们正在使用许多JavaScript库(并且可能也被JavaScript代码使用)。
So we prefer PascalCase for modules and classes, with members being camelCase. 所以我们更喜欢PascalCase用于模块和类,成员是camelCase。
module ExampleModule {
export class ExampleClass {
public exampleProperty: string;
public exampleMethod() {
}
}
}
The only other style rule I can think of is that constants are ALL_UPPER. 我能想到的唯一另一种风格规则是常量是ALL_UPPER。
You will notice that this blends in nicely with the following code: 您会注意到这与以下代码很好地融合:
Math.ceil(Math.PI);
Most importantly of all - keep consistent with the style you use as the style can imply meaning, so if you aren't consistent it will cause confusion. 最重要的是 - 保持与你使用的风格一致,因为风格可能暗示意义,所以如果你不一致,它将导致混乱。
Notice: Internal modules are namespaces. 注意:内部模块是名称空间。 The next version of TypeScript focuses on external modules from ECMAScript 6 , which are not namespaces.
下一版本的TypeScript 侧重于ECMAScript 6的外部模块 ,这些模块不是命名空间。
Microsoft didn't publish a naming guideline for internal modules in TypeScript. Microsoft没有在TypeScript中发布内部模块的命名准则。
An internal module is like a class with only static members: 内部模块就像一个只有静态成员的类:
module MyLib {
export function f1() {
}
export function f2() {
}
// ...
}
Languages that use pascal case for namespaces: C# , PHP . 使用pascal case作为名称空间的语言: C# , PHP 。
A name in camel case is reminiscent of the Google Style Guide for JSON : 驼峰案例中的名称让人联想到JSON的Google样式指南 :
Property names must be camel-cased, ascii strings.
属性名称必须是驼峰式的,ascii字符串。
… but an internal module is not a JSON object. ...但内部模块不是JSON对象。
Languages that use camel case for namespaces: ? 使用驼峰式命名空间的语言:? (Not Java, which uses lowercase).
(不是Java,使用小写)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.