I'm trying to add objects to an array with a specific id which I need to know inside the constructor. Will this work?
objectArray = [];
function newObject (name, age, eyeColour) {
this.name = name;
this.age = age;
this.eyeColour = eyeColour;
var id = *some integer*
this.id = id;
objectArray[id] = this; //This is the line in question.
}
Obviously this is just an example. In my real code I'm using the id in the id of 3 new DOM objects, so I need to have it available inside the constructor.