skaterdav85 Posted November 10, 2010 Share Posted November 10, 2010 I have an object literal: var Twitter = { freddurst: '', wesborland: '', ottoj: '', djlethal: '', samrivers: ''}; one of my functions is passed an argument whose value contains one of the property names of the Twitter object. How can I access it? function getTweets(twitName) { Twitter.twitName is undefined. twitName contains 'freddurst', 'wesborland' etc} Link to comment Share on other sites More sharing options...
Synook Posted November 10, 2010 Share Posted November 10, 2010 What do you mean? What does getTweets actually contain? var Twitter = { freddurst: '', wesborland: '', ottoj: '', djlethal: '', samrivers: ''};function getTweets(twitName) { alert(twitName.freddurst);}getTweets(Twitter); //alerts '' Link to comment Share on other sites More sharing options...
skaterdav85 Posted November 10, 2010 Author Share Posted November 10, 2010 getTweets is a function that either: 1. makes an ajax request to retrieve the latest tweets for the twitName, saves them in a property, and loads a sidebar div, or2. doesnt make the ajax request and just loads the latest tweets for that twitName which were stored in a property of the Twitter object function getTweets(twitName){ if(Twitter.twitName == ''){ //make ajax request and store it in Twitter.twitName, but twitName isnt a property of the Twitter object. //i want it to represent one of the properties in the Twitter object though, since twitName could be 'freddurst', 'wesborland' etc //load a sidebar div with the tweets for that twitName } else { //just load a sidebar div with the tweets stored in the proprety }} Link to comment Share on other sites More sharing options...
thescientist Posted November 10, 2010 Share Posted November 10, 2010 is it just a coincidence that you are using the argument name twitName with an example using members of the band Limp Bizkit? Link to comment Share on other sites More sharing options...
ShadowMage Posted November 10, 2010 Share Posted November 10, 2010 You can access properties of an object with a variable using array syntax:var prop = Twitter[twitName]; Link to comment Share on other sites More sharing options...
skaterdav85 Posted November 11, 2010 Author Share Posted November 11, 2010 is it just a coincidence that you are using the argument name twitName with an example using members of the band Limp Bizkit? lol no. twitName = Twitter username. I know there are a lot of LB haters out there but I am actually a huge fan. I am creating a mashup just for fun using Twitter, Youtube, Google Maps, and Flickr.You can access properties of an object with a variable using array syntax:var prop = Twitter[twitName];Thanks, that worked! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.