Adding variables to a function's scope during a call
<p>I want to allow a <code>locals</code> object to have all its variables be within the scope when a function is called. For example:</p>

<pre><code>function test() {
  console.log(string)
}

var locals = {
  string: 'test'
}

function callTest(fn, locals) {
  // INSERT MAGIC
  fn()
}

callTest(test, locals) // -&gt; should log 'test' without any errors
</code></pre>

<p>What I'm trying to avoid:</p>

<pre><code>function(locals) {
  with (locals) {
    console.log(string)
  }
}
</code></pre>

<p>Use case: I want to create a templating system with a callback.
The locals should really be locals, not a "locals" object.</p>

<pre><code>module.exports = function(callback) {
  callback(null, string)
}
</code></pre>

<p>Yes, I can do the following, but it's ugly. For now, this is how I'm doing it:</p>

<pre><code>module.exports = function(locals, callback) {
  callback(null, locals.string)
}
</code></pre>

<p>Is this possible at all, or even in any programming language?</p>
