nemobluesix Posted October 7, 2010 Share Posted October 7, 2010 hi,is there a way to access an objects member from another member of the same object? an example might be more explicitthis is what can be done var myObj={ "x":1, "y":2 }; this is what i would like to do var myObj={ "x":1, "y":x+1 }; Link to comment Share on other sites More sharing options...
nemobluesix Posted October 7, 2010 Author Share Posted October 7, 2010 obviously i'm a beginner with json. after more reading i came up to the conclusion that what i intended is an aberration .this would be right and somehow it serves my purpose. var myObj={ "x":1, "doSmth":function(){ alert(this.x+1) }}; Link to comment Share on other sites More sharing options...
ShadowMage Posted October 7, 2010 Share Posted October 7, 2010 I think it would work if you do it like this:var myObj={ "x":1, "y":this.x+1 };I'm not sure though. I haven't tested it. Link to comment Share on other sites More sharing options...
nemobluesix Posted October 8, 2010 Author Share Posted October 8, 2010 thanks for your reply,I did try with "this" but this.x+1 treats "this.x" as object, id does not give me the value "1"paste this in your browsers address bar java script:var myObj={ "x":1, "y":this.x+1 }; alert(myObj.y);//result: [object NodeList]1 it does not trow an error but it doesn't return what it should either. I don't need this for the moment but it would be nice to know Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.