Variable initialization with curly braces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick S

    Variable initialization with curly braces

    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?

    Code:
    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
  • Lasse Reichstein Nielsen

    #2
    Re: Variable initialization with curly braces

    Nick S <nrsutton@gmail .comwrites:
    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/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Jorge

      #3
      Re: Variable initialization with curly braces

      On Jun 28, 6:03 pm, Nick S <nrsut...@gmail .comwrote:
      >
      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.

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Variable initialization with curly braces

        Jorge wrote:
        On Jun 28, 6:03 pm, Nick S <nrsut...@gmail .comwrote:
        >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

        Comment

        • Nick S

          #5
          Re: Variable initialization with curly braces

          On Jun 28, 6:17 pm, Lasse Reichstein Nielsen <l...@hotpop.co mwrote:
          Nick S <nrsut...@gmail .comwrites:
          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/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'
          Thanks to everyone for your answers

          Comment

          Working...