Thursday, May 23, 2024
36
rated 0 times [  38] [ 2]  / answers: 1 / hits: 18050  / 13 Years ago, sat, december 31, 2011, 12:00:00

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.


More From » naming-conventions

 Answers
61

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.


[#88302] Thursday, December 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamilab

Total Points: 687
Total Questions: 88
Total Answers: 86

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
;