eval returning variable name instead of undefined. (javascript)
<p><strong>Update</strong>
The code for the function / class is stored in a string which is why I cannot call it directly. The idea is to do introspection on the object and enumerate its data members which works when it is a function but doesn't work when a variable like the one below is eval'ed.</p>

<p>I am trying to evaluate an object in javascript. Something like this.</p>

<pre><code>var myObj {
   greet: "Greeting",

   myPrint: function() {
      alert("hello");
   }
};
</code></pre>

<p>The idea is to be able to run this in eval and get the variable name somehow (myObj) or an object created. I have experimented with various methods using eval but cannot figure this out. This works when I have something like this.</p>

<pre><code>function myObj() {
   this.greet  = "Greeting";

   this.myPrint = function() {
      alert("hello");
   }
};
</code></pre>

<p>Running eval("(" + code + ")"); where code is a string containing the above function returns myObj() to me. </p>

<p><strong>Update 2</strong>
So basically I want to evaluate something like this. 
eval("var x = 5"); and I am trying to get x. Since its a string being evaluated, even though it gets added to the window namespace, there is no way to decipher it apart from parsing the string. Now this is just a simple example but as I said, it's a little difficult with the 1st piece of code. As I said... 
eval("function test() { return 'hello'; }"); return test() which is similar to what I am expecting for the "var x = 5" statement.</p>

<p>Is there a way to do this similarly for the 1st case which I am missing ?
Thanks</p>
