tags:

views:

44

answers:

3
a = {x :5 , y: 6};

Anyone know what is this ?
I want to know what the a var type. in many js tut, they don't tell about this. Just tell:
var a = new a();. anyone can give me a link about this type ({x :5 , y: 6});
Sorry, bad question and bad english

+3  A: 

a is an "object".

Outside of Javascript it is usually known as an associative array / dictionary.

To declare a with the new expression (not recommended):

var a = new Object();
a.x = 5;
a.y = 6;
KennyTM
but in many js tut, to declare object -> var a = new a();. I don't see anything about this .
Snoob
@Snoob: Because `a` is not a type. To declare an object using the `new` expression, you need to use `var a = new Object();`
KennyTM
Thanks your link
Snoob
+1  A: 

That is a javascript Object that contains two properties: x and y.

You can access them like this:

alert(a.x + x.y) // should display "11"

a.x = 10 // this sets x to 10

a["x"] = 10 // alternate way to access a property
Pablo Fernandez
+2  A: 

It is called "Object". Read here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object

To see what type of variable you have, and what constructor was used to create it, you can run this code:

a = {x :5 , y: 6};
alert("TypeOf a = " + typeof(a) + "\nConstructor of a = " + a.constructor);
AndreyKo
But in your link : var o = new Object();.
Snoob
{} in javascript is a short way to write "new Object", just like "[]" is a short way to write "new Array"
AndreyKo
thanks. i knew ......
Snoob
Read "Creating Objects" here: http://en.wikipedia.org/wiki/JavaScript_syntax#Creating_objects
AndreyKo