HighDots Forums  

Variable initialization with curly braces

Javascript JavaScript language (comp.lang.javascript)


Discuss Variable initialization with curly braces in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Nick S
 
Posts: n/a

Default Variable initialization with curly braces - 06-28-2008 , 12:03 PM






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

Reply With Quote
  #2  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: Variable initialization with curly braces - 06-28-2008 , 12:17 PM






Nick S <nrsutton (AT) gmail (DOT) com> writes:

Quote:
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.

...

Quote:
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.'


Reply With Quote
  #3  
Old   
Jorge
 
Posts: n/a

Default Re: Variable initialization with curly braces - 06-28-2008 , 12:19 PM



On Jun 28, 6:03*pm, Nick S <nrsut... (AT) gmail (DOT) com> wrote:
Quote:
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.


Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Variable initialization with curly braces - 06-28-2008 , 12:41 PM



Jorge wrote:
Quote:
On Jun 28, 6:03 pm, Nick S <nrsut... (AT) gmail (DOT) com> 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


Reply With Quote
  #5  
Old   
Nick S
 
Posts: n/a

Default Re: Variable initialization with curly braces - 06-28-2008 , 01:11 PM



On Jun 28, 6:17 pm, Lasse Reichstein Nielsen <l... (AT) hotpop (DOT) com> wrote:
Quote:
Nick S <nrsut... (AT) gmail (DOT) com> 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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.