title: javascript: access function in closure
body: <p>I have the name of a function in a variable, but everything is within a closure. With this variable I want to call the function, something like this</p>
  
  <pre><code>(function(func) {
        this[func]() ;         // doesn't work
  
        function bar() {}
        function foo() {}
  })('bar') ;
  </code></pre>
  
  <p>Is something like this possible or should I, for example, add the functions to a variable, like</p>
  
  <pre><code>(function(func) {        
        var ns = {
            bar: function() {},
            foo: function() {}
        };
  
        ns[func]() ;         // OK
  })('bar') ;
  </code></pre>