0

In JS or Jquery, is it possible to convert a string into a function, and run it ?

Something like this :

var s = 'var n = 0; n++; alert(n)';
convertStringToFunction(s); // this would show an alert with the content '1';

My actual case is not this, it's just a simplified example. What i'm trying to achieve is a way to generate a JS code in runtime and execute it.

Thanks !

delphirules
  • 6,443
  • 17
  • 59
  • 108

0 Answers0