title: Javascript Dynamic Function Call with Name
body: <p>So I have the following pseudo Javascript code:</p>
  
  <pre><code>var Class = (function(window, document, $) {
      function meth_1()
      {
          //some code
      }
  
      function meth_2()
      {
          //some code
      }
  
      function meth_3()
      {
          //some code
      }
  
      function meth_4()
      {
          //some code to call other three functions dynamically
      }
  
      Class = {
          meth_1: meth_1,
          meth_2: meth_2,
          meth_3: meth_3,
          meth_4: meth_4
      };
      return Class;
  
  })(window, document, jQuery);
  </code></pre>
  
  <p>In the <code>meth_4</code> function, I want to call the other 3 functions dynamically by passing the function name as a string. How can I do this?!</p>
  
  <p>In this <a href="https://stackoverflow.com/questions/10419538/javascript-dynamic-function-name">related StackOverflow question</a>, the answer provides a solution to how this could be done in window scope i.e. <code>window[function_name]()</code>. However, I'd like to know how I can do it in my particular circumstance.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The answer I selected works ok. You could also do the following:</p>
  
  <pre><code>var Class = (function(window, document, $) {
      var meth_func = {
          meth_1: function(){/**your code**/},
          meth_2: function(){/**your code**/},
          meth_3: function(){/**your code**/}            
      }
  
      function meth_4(func_name)
      {
          meth_func[func_name]();
      }
  
      Class = {
          meth_4: meth_4
      };
      return Class;
  
  })(window, document, jQuery);
  </code></pre>
  
  <p>This would probably work better if you wanted to make private those three functions being called dynamically.</p>