Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I name things with initial capital letters?

Tags:

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 this:

function doStuff() {}  var simpleVar = 'some stuff',     myAry = [],     myObj = {}; 

... But I know I am supposed to name some things with capital first letters. I just don't know WHEN this rule applies. Hope somebody can make things a bit clearer to me.

like image 418
patad Avatar asked Dec 31 '11 08:12

patad


People also ask

Should names always start with a capital letter?

People's names are proper nouns, and therefore should be capitalized. The first letter of someone's first, middle, and last name is always capitalized, as in John William Smith.

Do you capitalize the when naming something?

If you are using the publication name as a modifier, you can just omit the “the.” For example, the official name of The New York Times is The New York Times, so if you are following AP style and writing something like “I had a book review in The New York Times,” you capitalize the word “the.” But, if you are writing ...

When should words be capitalized?

In English, a capital letter is used for the first word of a sentence and for all proper nouns (words that name a specific person, place, organization, or thing). In some cases, capitalization is also required for the first word in a quotation and the first word after a colon.


2 Answers

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.

like image 63
louis.luo Avatar answered Sep 20 '22 04:09

louis.luo


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); 
like image 22
Peter-Paul van Gemerden Avatar answered Sep 18 '22 04:09

Peter-Paul van Gemerden