Trying to understand how to objects within objects

S

steven.harms

Hi,

I. Multiple layers of dereferencing:

I took this example from Amy Hoy's javascript tutorial:

var foo = {
bar:"baz",
zort:"narf",
aNumber:5,
anArray:['banana','plaintain','ugli fruit'],
anotherObject: {
king: "hobo"
},
anotherObject2: {
king: "hobo2"
},
doStuff:function() {
alert("I'm doing stuff!")
}
}

When I do

alert(foo.bar) --> "baz" comes up. Great!

Now this works....

// This works
alert(foo.anotherObject.king)

But say i wanted to, based on input, return out of anotherObject or
anotherObject2.

var x="anotherObject"

alert(foo.x.king)

does not work.

Hrm. Is this multiple layer of dereferencing possible?

II. Is there a tutorial for 'intermediate' javascripters?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top