JSON array problem

X

xdevel1999

Hi, I have the following problem:
when I try to access to the array in Big object I have 'Big is not
defined'
but
when I try to access to the function in Low object I have no error!!!!
WHY??

Big =

{
One: [1, 2, 4],
Two: [1, Big.One, 5]

};

alert(Big.Tow) // error

Low =
{
One: function()
{

},
Two: function()
{
Low.One();
}
};

Low.Two(); // no error

Thank
 
X

xdevel1999

None of these are valid JSON objects; that's the main problem.

why is the syntax incorrect?
second case, 'Low' _is_ defined when you try to access it, which is in
the line "Low.Two();".

Yes I can understand but this works...I'm confused

Low =
{
One: function()
{
alert(Low.b); // here the object Low is not already defined!
},
Two: function()
{
Low.One();
},

b:"xxx"
};
 
R

Richard Cornford

why is the syntax incorrect?


Yes I can understand but this works...I'm confused

Low =
{
One: function()
{
alert(Low.b); // here the object Low is not already defined!
},
Two: function()
{
Low.One();
},

b:"xxx"



};

It is all about sequence. The property accessor - Low.One - in the
function is not evaluated until the function is called, and that is
after the value resulting form the object literal has been assigned to
- Low -, and so Low is defined and its value is an object reference at
that point.

In (simplified):-

Big = { One:'x', Two: [1, Big.One, 5]} ;

- the value of the object literal has to be determined before it can
be assigned to - Big -, and in order to determine that value it is
necessary to determine the value of the array literal - [1, Big.One,
5] -, which in tern requires the evaluation of the property accessor -
Big.One -. But evaluating the property accessor - BigOne - requires
reading the value of the 'One' property of an object referred to by -
Big -, but - Big - has not yet been assigned any value because we are
still in the process of working out what that value should be.

Richard.
 

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,138
Messages
2,570,802
Members
47,348
Latest member
nethues

Latest Threads

Top