How to turn a String into a JavaScript function call?

JavascriptWeb DevelopmentFront End Technology

To turn a string into a JavaScript function call, try to run the following code

Example

Live Demo

<html>
   <body>
      <script>
         function myFunction(argument) {
            alert('My function ' + argument);
         }
         functionName = 'myFunction';
         window[functionName]('is working.');
      </script>
   </body>
</html>
raja
Published on 31-Jan-2018 12:41:05
Advertisements