title: Changing function's scope
body: <p>I recently discovered <code>with</code> in javascript to execute a block with an object as the current scope. I'm curious if there is some javascript magic to do the same thing with a function and call it in a different scope.</p>
  
  <p>Example:</p>
  
  <pre><code>var scope = { foo: 'bar' },
      foo   = 'baz';
  
  function func(){
    return foo;
  }
  
  with(scope){
    foo;    // foo is 'bar'
    func(); // foo is still 'baz' 
  }
  </code></pre>
  
  <p>In the example, <code>with</code> changes the scope of the variable <code>foo</code>, but the function still uses the scope outside of <code>with</code> where it was defined. Any suggestions for how to alter or rebind the scope of a function?</p>