Variable name as a string in Javascript
<p>Is there a way to get a variable name as a string in Javascript? (like NSStringFromSelector in Cocoa)</p>

<p>I would like to do like this:</p>

<pre><code>var myFirstName = 'John';
alert(variablesName(myFirstName) + ":" + myFirstName);

--&gt; myFirstName:John
</code></pre>

<p>-- added</p>

<p>I'm trying to connect a browser and another program using JavaScript. I would like to send instance names from a browser to another program for callback method.</p>

<pre><code>FooClass = function(){};
FooClass.someMethod = function(json) {
  // Do something
}

instanceA = new FooClass();
instanceB = new FooClass();
doSomethingInAnotherProcess(instanceB); // result will be substituted by using instanceB.someMethod();
</code></pre>

<p>....</p>

<p>[From another program]</p>

<pre><code>evaluateJavascriptInBrowser("(instanceName).someMethod("resultA");");
</code></pre>

<p>In PHP:
<a href="http://stackoverflow.com/questions/255312/how-to-get-a-variable-name-as-a-string-in-php/255335#255335">How to get a variable name as a string in PHP?</a></p>
