From: GTalbot on 28 May 2010 10:45 Hello all, While reading this newsgroup, I remember reading that using capitalized functionname is bad form (... or can create problems, I am not sure). I can't remember why. Apparently function test() { ... } is ok but function Test() { ... } is not ok. Can someone elaborate on this? regards, Gérard
From: Ry Nohryb on 28 May 2010 10:54 On May 28, 4:45 pm, GTalbot <newsgr...(a)gtalbot.org> wrote: > Hello all, > > While reading this newsgroup, I remember reading that using > capitalized functionname is bad form (... or can create problems, I am > not sure). I can't remember why. > > Apparently > > function test() { ... } is ok > > but > > function Test() { ... } is not ok. > > Can someone elaborate on this? > > regards, Gérard It's only a convention: if you only capitalize constructors, you can instantly recognize them as being a constructor (and remember to put the (often required) new in front of the call). Other than for that reason, you can name any f() as you like, capitalized or not, it won't do any harm, afaik. -- Jorge.
From: Richard Cornford on 28 May 2010 10:59 On May 28, 3:45 pm, GTalbot wrote: > Hello all, > > While reading this newsgroup, I remember reading that using > capitalized functionname is bad form (... or can create > problems, I am not sure). I can't remember why. > > Apparently > > function test() { ... } is ok > > but > > function Test() { ... } is not ok. > > Can someone elaborate on this? It is style thing. It is common practice to use initial uppercase for the names of functions that are intended to be used as constructors, and use non-upper case initial letters on all functions/methods that are not intended to be used as constructors. Or more generally, the initial uppercase names are used to indicate things that are implementing the (OO) 'class' concept in javascript. Richard.
From: GTalbot on 28 May 2010 11:14 On 28 mai, 10:59, Richard Cornford <Rich...(a)litotes.demon.co.uk> wrote: > On May 28, 3:45 pm, GTalbot wrote: > > > Hello all, > > > While reading this newsgroup, I remember reading that using > > capitalized functionname is bad form (... or can create > > problems, I am not sure). I can't remember why. > > > Apparently > > > function test() { ... } is ok > > > but > > > function Test() { ... } is not ok. > > > Can someone elaborate on this? > > It is style thing. It is common practice to use initial uppercase for > the names of functions that are intended to be used as constructors, > and use non-upper case initial letters on all functions/methods that > are not intended to be used as constructors. Ry Nohryb and Richard Cornford: thank you for your quick and clear answers/replies. regards, Gérard
From: Johannes Baagoe on 28 May 2010 12:17 Richard Cornford : > more generally, the initial uppercase names are used to indicate > things that are implementing the (OO) 'class' concept in javascript. I think the convention goes back to Pascal and similar early languages that allowed the users to create new types - and that coincidentally allowed lower case for the first time. People had to distinguish between such types and variables, and some took the habit of doing so by the upper or lower case of the initial letter. Similar concerns led to similar results with typedefs in C, etc. Later, when special functions were invented to return complex data that is similar in structure and behaviour, it seemed logical to give such functions a capital letter, too. "a = Foo()" and "a = new Foo()" look and behave a lot like "Foo a". -- Johannes
|
Pages: 1 Prev: determining Adobe Acrobat PDF plugin version Next: innerHTML and nodeType |