/    Sign up×
Community /Pin to ProfileBookmark

Get a variable name in string format

I don’t believe it is possible but if anyone knows how to convert a variable name into a string representation please let me know. Thanks.

For example (purely for illustration purposes as this is not exactly the code):

[CODE]
var theVar = “123”;
doSomething(theVar); // this should result in a call to doSomethingNew()

var theOtherVar = “456”;
doSomething(theOtherVar); // this should result in a call to dontDoSomethingNew()

function doSomething(myVar) {

var simpleVar = “theVar”;
// TO DO: get the name of the variable in String
var testStrVar = myVar.convertString(); // pseudo code as I don’t know exact syntax if any to do this

if (testStrVar == simpleVar) {
doSomethingNew();
} else {
dontDoSomethingNew();
}

}[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyNov 25.2008 — You cannot retrieve the variable's name which was used as an argument to a function. The variable name would have to actually be passed as a separate string value.
Copy linkTweet thisAlerts:
@omertaauthorNov 25.2008 — okay - it was a long shot but I thought I'd ask it all the same. thanks
×

Success!

Help @omerta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...