Capitalized functionname: why is it bad?

Discussion in 'Javascript' started by GTalbot, May 28, 2010.

  1. GTalbot

    GTalbot Guest

    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
     
    GTalbot, May 28, 2010
    #1
    1. Advertising

  2. GTalbot

    Ry Nohryb Guest

    On May 28, 4: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?
    >
    > 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.
     
    Ry Nohryb, May 28, 2010
    #2
    1. Advertising

  3. 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.
     
    Richard Cornford, May 28, 2010
    #3
  4. GTalbot

    GTalbot Guest

    On 28 mai, 10:59, Richard Cornford <>
    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
     
    GTalbot, May 28, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,226
    Smokey Grindel
    Dec 2, 2006
  2. rantingrick
    Replies:
    44
    Views:
    1,298
    Peter Pearson
    Jul 13, 2010
  3. Peng Yu
    Replies:
    0
    Views:
    207
    Peng Yu
    Jul 16, 2010
  4. -Lost
    Replies:
    12
    Views:
    301
    Elegie
    Jan 31, 2007
  5. Replies:
    11
    Views:
    505
    Jeff Higgins
    Oct 10, 2012
Loading...

Share This Page