<html>
<head>
<title>Ohi</title>
<script>
test = { "People": { }, 'addPerson': function ( sName ) { this.People[ sName ] = new Person( sName ); } }
test.addPerson( 'Fred' );
function Person( sName )
{
this.sName = sName;
this.Hats = [];
var oPar = this;
this.Hats[ "Red" ] = new Hat( oPar, "red" );
this.Hats[ "Yellow" ] = new Hat( oPar, "yellow" );
}
function Hat( oParent, sColor )
{
this.parent = oParent;
this.sColor = sColor;
this.changeColor = function( sNewColor )
{
this.sColor = sNewColor;
return true;
}
this.OwnerName = function ( )
{
return this.parent.sName;
}
}
console.log( test.People[ "Fred" ] );
console.log( test.People[ "Fred" ].Hats );
console.log( test.People[ "Fred" ].Hats.length );
</script>
</head>
<body>
Ohi
</body>
</html>