Hello all

I am looking to write a simple library for use with the canvas element, but I am getting a little confused about constructors.

Suppose I have the following code:

animal={};
animal.details=function() {
this.name="rabbit";
this.location="field";
}

pet1 = new animal.details();
alert(pet1.name);

This makes an "animal" object, containing a details object correct? This code seems to work, but I would be interested in other ways of writing it.

I tried:

function animal()
{
function details() {
this.name="rabbit";
this.location="field";
}
}

pet1 = new animal();
alert(pet1.details.name);

I thought perhaps creating an animal object would automatically create other objects defined inside. Apparently not, this nested function idea doesn't seem to work.

I would be interested to know why the above code does not work, and any alternative ways of rewriting the first piece of code please.

Thank you

Matt