I'm relatively new to JS. I read somewhere that I can do the following:
function stuff ( item ) {
this.valuable = item;
}
my_junk = new stuff( "teddy bear" );
function containers( container_item ) {
this.container = container_item;
}
my_container = new containers( "house", my_junk );
document.write( my_container.my_junk.valuable );
**********************
But I can't get it to work, however, I've seen it done this way [and I can get this to work]:
**********************
my_container = new containers( "house" );
my_container.my_junk = my_junk;
document.write( my_container.my_junk.valuable );
**********************
Did mis-read something? I'd prefer to use the first syntax to make life easier. What am I doing wrong?
mike
function stuff ( item ) {
this.valuable = item;
}
my_junk = new stuff( "teddy bear" );
function containers( container_item ) {
this.container = container_item;
}
my_container = new containers( "house", my_junk );
document.write( my_container.my_junk.valuable );
**********************
But I can't get it to work, however, I've seen it done this way [and I can get this to work]:
**********************
my_container = new containers( "house" );
my_container.my_junk = my_junk;
document.write( my_container.my_junk.valuable );
**********************
Did mis-read something? I'd prefer to use the first syntax to make life easier. What am I doing wrong?
mike