473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JavaScript Object Notation

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?

Apr 30 '07 #1
5 1218
On May 1, 8:36 am, gh0...@pacbell.net wrote:
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 }
--
Rob

Apr 30 '07 #2
RobG wrote:
On May 1, 8:36 am, gh0...@pacbell.net wrote:
>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 }
Really? I always get "x has no properties."

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 1 '07 #3
On May 1, 12:30 pm, -Lost <maventheextrawo...@techie.comwrote:
RobG wrote:
On May 1, 8:36 am, gh0...@pacbell.net wrote:
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 }

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 );
--
Rob

May 1 '07 #4
RobG wrote:
On May 1, 12:30 pm, -Lost <maventheextrawo...@techie.comwrote:
>RobG wrote:
>>On May 1, 8:36 am, gh0...@pacbell.net wrote:
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 }
Really? I always get "x has no properties."

I didn't say it worked... :-x
Oh! Hehe. ;)
I guess the closest is:

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

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 1 '07 #5
Gecko has two beautiful methods - getter and setter.

var x = {
one: 1,
get two() {
return this.one + 1;
}
}

See http://developer.mozilla.org/en/docs...rs_and_Setters
May 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary | last post by:
Hi, I am developing desktop application. In the desktop application am loading a html page, i want to acces html element value from C# code. Can anyone help me? how to access a html element or...
5
by: Digital | last post by:
Hi, I'm looking for links to the JS object model for the not-as-popular properties and methods. I've found things like hasOwnProperty, isEnumerable, ===, prototype, and others by searching for...
2
by: mikevanoo | last post by:
Hi, Can anyone work out why the following doesn't work. For some reason, when you dynamically add a button to the document from a Javascript object it can't then reference the properties of the...
6
nirmalsingh
by: nirmalsingh | last post by:
hi all, how to pass javascript object as url parameter and get that object by c#(request.querystring..)something like that? thanx in advance
3
by: SirCodesALot | last post by:
Can someone help me with this syntax, I have the following javascript object: function foo() { this.myFooVar = 0; this.doThis = function (){ var ao = new AnotherObject();...
1
by: KDawg44 | last post by:
HI, I am using jsgraph to draw some graphs. I want to be able to update these graphs by calling a javascript function to update data. I have a div to display the graph that looks like this: ...
23
Frinavale
by: Frinavale | last post by:
JavaScript is a very strange place for me... So, I decided that, before I attempt to create an Object, I should first learn about Objects. I had actually created one before with the help of a...
3
Frinavale
by: Frinavale | last post by:
I've created a few ASP.NET Ajax Enable Server controls. There are 2 components to these controls: a server side Object that deals with the server side stuffs, and a client side Object that deals...
5
by: Yene | last post by:
What is a JavaScript Object? if there is a such thing help pls.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.