Variable initialization with curly braces

Discussion in 'Javascript' started by Nick S, Jun 28, 2008.

  1. Nick S

    Nick S Guest

    I've just been trying to de-construct the jQuery tooltop plugin in an
    attempt to better my javascript coding and I've come across a question
    google can't help me with.

    What is the deal with initializing a variable like this?

    var helper = {},
    // the current tooltipped element
    current,
    // the title of the current element, used for restoring
    title,
    // timeout id for delayed tooltips
    tID,
    // IE 5.5 or 6
    IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
    // flag for mouse tracking
    track = false;

    What are the first curly braces?

    Thanks
     
    Nick S, Jun 28, 2008
    #1
    1. Advertising

  2. Nick S <> writes:

    > What is the deal with initializing a variable like this?
    >
    > var helper = {},


    This declares the "helper" variable and assigns it a value that is
    a new object.

    ...

    > What are the first curly braces?


    The expression "{}" is an object literal expression that evaluates to
    a new object with no extra properties. It's equivalent to
    "new Object()".

    /L
    --
    Lasse Reichstein Nielsen
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jun 28, 2008
    #2
    1. Advertising

  3. Nick S

    Jorge Guest

    On Jun 28, 6:03 pm, Nick S <> wrote:
    >
    > What is the deal with initializing a variable like this?
    >
    > var helper = {},
    > (...)
    > What are the first curly braces?
    >


    It means "helper is an object".
    It's the "literal notation" way of saying helper= new Object();

    See :
    <http://www.google.com/search?q=object+initialization+javascript>

    --Jorge.
     
    Jorge, Jun 28, 2008
    #3
  4. Jorge wrote:
    > On Jun 28, 6:03 pm, Nick S <> wrote:
    >> What is the deal with initializing a variable like this?
    >>
    >> var helper = {},
    >> (...)
    >> What are the first curly braces?
    >>

    >
    > It means "helper is an object".


    No, it means helper currently *stores a reference* to a (native Object) object.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Jun 28, 2008
    #4
  5. Nick S

    Nick S Guest

    On Jun 28, 6:17 pm, Lasse Reichstein Nielsen <> wrote:
    > Nick S <> writes:
    > > What is the deal with initializing a variable like this?

    >
    > > var helper = {},

    >
    > This declares the "helper" variable and assigns it a value that is
    > a new object.
    >
    > ..
    >
    > > What are the first curly braces?

    >
    > The expression "{}" is an object literal expression that evaluates to
    > a new object with no extra properties. It's equivalent to
    > "new Object()".
    >
    > /L
    > --
    > Lasse Reichstein Nielsen
    > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    > 'Faith without judgement merely degrades the spirit divine.'


    Thanks to everyone for your answers
     
    Nick S, Jun 28, 2008
    #5
    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. Dustin D.
    Replies:
    0
    Views:
    2,310
    Dustin D.
    Aug 27, 2003
  2. Geathaa
    Replies:
    1
    Views:
    538
    Martin Honnen
    Sep 12, 2003
  3. TJ
    Replies:
    5
    Views:
    580
  4. Replies:
    10
    Views:
    781
    John Machin
    May 17, 2009
  5. Ken Fine
    Replies:
    2
    Views:
    177
    Ken Fine
    Feb 24, 2004
Loading...

Share This Page