title: Call function dynamically in Javascript
body: <p>I want to dynamically call a function from a string like "User.find". A script would call the function find() in the object User if the function exists. Here's what I tried:</p>
  
  <pre><code> var User = {};
   User.find = function(){
       return 1;
   }
  
   var input = 'User.find';
   var some_data_array = {name: 'John Doe'};
   var method = input.toString().split('.');
   var nameObj = method[0].substring(0,1).toUpperCase() + method[0].substring(1);
   var methodToCall = method[1];
  
   nameObj.call(methodToCall, some_data_array);
  </code></pre>
  
  <p>But it always returns:</p>
  
  <pre><code> nameObj.call(methodToCall, some_data_array);
   TypeError: Object User has no method 'call'
  </code></pre>
  
  <p>Any idea? I can't use window since it is a node.js problem, the script is not executed in the browser.</p>