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.
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.
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 ...
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With