Capitalized functionname: why is it bad?

G

GTalbot

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
 
R

Ry Nohryb

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.
 
R

Richard Cornford

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.
 
G

GTalbot

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top