Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Let’s say below is the String I’ve in JavaScript: 

var fnStr = "function(){blah1;blah2;blah3; }" ;

I want to define fn as below to the code: 

var fn = function(){blah1;blah2;blah3; } ;

Can anyone tell me how I can do it?

1 Answer

0 votes
by (19.7k points)

You can use the Function object like below: 

var adder = new Function("a", "b", "return a + b");

 Interested in Java? Check out this Java tutorial by Intellipaat. 

Browse Categories

...