Question: I'm defining a javascript object and setting its properties and methods like this: 

```
function MyObject()
{
  this.prop1 = 1;
  this.prop2 = 2;

  this.meth1=meth1;
}

function meth1()
{
  // do soemthing
}

```

All is fine. My question is how can i have an object be a property of MyObject? I actually want an 'associative array' as a property something along these lines: 

```
function MyObject()
{
  this.obj['x'] = 'val1';
  this.obj['y'= = 'val2';

  this.prop1 = 1;
  this.prop2 = 2;

  this.meth1=meth1;
}

```

I have tried declaring obj in MyObject like this: `obj = new Object`; with no luck, obj is not being interpreted as a property.

Any clues as to what i'm doing wrong?

thanks

Answer: 
Do you mean:

```
function MyObject() {
  this.obj = {'x': 'val1', 'y': 'val2'};

  this.prop1 = 1;
  this.prop2 = 2;

  this.meth1=meth1;
}

```

?

Now you can say:

```
new MyObject().obj.x  //`val1`

```

Alternative syntax:

```
this.obj = {};
this.obj.x = 'val1';
this.obj.y = 'val2';

```
It's often easiest to use the object literal notation:

```
function MyObject()
{
  // obj as an object literal
  this.obj = {
     x: "val1",
     y: "val2",
     z: "val3"
  };

  this.prop1 = 1;
  this.prop2 = 2;

  this.meth1=meth1;
}

```