JavaScript Object Notation

G

gh0st1

Is it possible to have something like the following so that 'three'
can access 'one':

var x = {
one: 1,
two: { three:this.one } // Or parent.one ?
}

If not (which I have nearly come to a conclusion on) what is the next
best way to accomplish this?
 
R

RobG

Is it possible to have something like the following so that 'three'
can access 'one':

var x = {
one: 1,
two: { three:this.one } // Or parent.one ?

Functions have a this keyword whose value is set by the calling
function when the function is called, plain object don't have a this
property. You can use:

two: { three: x.one }
 
L

-Lost

RobG said:
Functions have a this keyword whose value is set by the calling
function when the function is called, plain object don't have a this
property. You can use:

two: { three: x.one }

Really? I always get "x has no properties."
 
R

RobG

Really? I always get "x has no properties."

I didn't say it worked... :-x

I guess the closest is:

var x = { one: 1 };
x.two = { three: x.one};
alert( x.two.three );
 

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
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top