title: Execute JavaScript code from a string
body: <p>I have a javascript code created server side and passed to the client as a string by a rest request. I am trying to execute the code retrieved.
  Any help would be appreciated.</p>
  
  <p>Server side. The javascript code stored in a string. </p>
  
  <pre><code>(function() {
  
  function createChart(selector) {
      $(selector).highcharts({
          chart: {
              type: 'column',
          },
          xAxis: {
              crosshair: true,
              type: "category"
          },
          yAxis: {
              min: 0,
              title: {
                  text: null
              }
          },
          series: [{
  
              data: datas    
          }],
      });
  }
  
  function render() {
      createChart('#chart');
  }
  return {
      render: render
  }
  }())
  </code></pre>
  
  <p>Client side (angular js)</p>
  
  <pre><code>    .controller('ChartController', ['$scope', 'charts',function ($scope, charts) {
  
          var test = charts.data;//contains the javascript code send by a rest request
          eval(test); 
          test.render(); 
  
  }])
  </code></pre>
  
  <p>The execution of the script in the client side returns "test.render is not a function" in chrome</p>
  
  <p>Any advices ?</p>
  
  <p>Thank you very much </p>