title: new Function() to anonymous function in Javascript
body: <p>Need to convert the below newFunction() to its equivalent anonymous function</p>
  <pre><code>MyFunc.createShape=function(shapeName,i,p){
  
    var funcBody=&quot;this.create(&quot;+shapeName+&quot;._TYPE,i,p);&quot;
    var finalFunc=new Function(i,p,funcBody);
  
  }
  </code></pre>
  <p>shapeName is called with 100s of different values like Rectangle,Square,Circle,etc.</p>
  <p>What I have tried is</p>
  <pre><code>  var global=&quot;&quot;;
    MyFunc.createShape=function(shapeName,i,p){
  
      global=shapeName;
      var finalFunc=function(i,p){
           this.create(global+&quot;._TYPE&quot;,i,p);
      };    
  
    }
  </code></pre>
  <p>The issue is in newFunction parameter is treated as a variable/object while my anonymous function variable is treated as a String .</p>
  <pre><code>new Function(i,p,funcBody); 
  At runtime is evaluated as
  
  function(i,p){
           this.create(Rectangle._TYPE,i,p);
      };
  </code></pre>
  <p>While my code at runtime</p>
  <pre><code>function(i,p){
           this.create(&quot;Rectangle._TYPE&quot;,i,p);
      };
  </code></pre>
  <p>How do I modify my anonymous function to behave same as the newFunction()</p>