When should I name things with initial capital letters?

后端 未结 3 1672
忘了有多久
忘了有多久 2020-12-29 06:29

I have always wondered when to use identifiers (for example, functions) with capital first letter instead of camel case. I always write my JS in camel case like thi

3条回答
  •  不知归路
    2020-12-29 07:13

    According to the book "Javascript: the good parts", you should only capitalise the first character of the name of a function when you need to construct the object by "new" keyword.

    This is called "the Constructor Invocation Pattern", a way to inherits.

提交回复
热议问题