How can I execute a JS function from the top of the stack?
<p>I'd like to execute a function from the top of the stack.  That is, any variables defined with "var" should be defined in the global sense.  Is this possible?  fn.call(window) doesn't work.</p>

<pre><code>&lt;script&gt;
  var foo = "I am top level foo.";

  var fn = function(){
    var foo = "Setting foo from in a function";
  }

  fn.call(window);  //doesn't work, var is still set locally in fn.
  alert(foo);  //desired effect will alert "setting foo from in a function"
&lt;/script&gt;
</code></pre>

<p><strong>Please note:</strong>  I am fully aware that not specifying "var" makes an item a global variable.  The problem is that I can not specify the contents of "fn", it is user-defined, but expected to be run from the top level.</p>

<p>I'm willing to use eval if necessary.</p>
