Use eval() with different local scope
<p>I would like to know how it is possible to call eval() with data from a different local scope.</p>

<p>Something like:</p>

<pre><code>function doSomething() {
    var y = 1;
    print_and_eval('y+1');
}

function print_and_eval(data) {
    print(data);
    eval(data);
}
</code></pre>

<p><strong>Edit:</strong>
- It is safe to use eval() in my case. Please do not recommend this as a solution.
- The main problem is, that I have local variables in doSomething() which are not defined in print_and_eval(). The evaluation then leads to an 'ReferenceError: y is not defined' error.</p>

<pre><code>js&gt; print_and_eval('var a = {x:1}')
var a = {x:1}
js&gt; print_and_eval('print(a.x)')    
print(a.x)
typein:3012: TypeError: a is null
</code></pre>

<p>I would like to receive the output '1' in this case.</p>
