When should I name things with initial capital letters?

后端 未结 3 1650
忘了有多久
忘了有多久 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:03

    The convention is to name constructor functions (i.e. functions that will be used with the new keyword) with starting capital.

    function MyType(simpleVar) {
        this.simpleVar = simpleVar;
    }
    
    myObject = new MyType(42);
    

提交回复
热议问题