Jay Braun
9/30/2015 6:28:00 PM
I am having some trouble experimenting with 'new Function()' as an alternative to 'eval()'.
In my current application, a server-side C program produces, upon request from the client, a JavaScript file that begins:
function funcName(arg1, arg2, arg3) {
//and has many statements
}
which is executed on the client side with:
filerequest.onreadystatechange = function() {
if (filerequest.readyState==4 && filerequest.status==200) {
var e = eval(filerequest.responseText);
funcName(a1, a2, a3);
}
}
The function is called/executed successfully because the server-side file contains the entire function.
Simple on-line examples of 'new Function()' show the "new" function being constructed in-line by some JavaScript code. That's not what is occurring here, and my attempts to apply the examples have failed. In particular, the browser console indicates that funcName() is not recognized.
Do I need to change the server-side file to use 'new Function()'? And in the above example, how must I alter the client-side code that invokes the generated function? I am free to change either or both of these.
Jay