How Do I Return Eval(code) And Get An Object Back With Javascript?
I have this bit of code. What I want it to do is is load a .js file and then run it. wWen it runs I want it to return a parameter or even better an object. This is the code in my p
Solution 1:
Another solution I found is to encapsulate your string to be eval'd inside a function, which is quite simple.
return eval("(function() {" + xhr.responseText + "})();");
Solution 2:
You cannot use return outside of a function. But to return a value from eval you can use the following syntax-
eval('var IO = function(){this.run = true; return "io";};{IO};')
Solution 3:
Problem is, you can't return outside of a function. What you'll need to is to return IO; from your runCode function after the request completes.
Solution 4:
Remove the new statement
var IO = function(){ 
    this.run = true; 
    return 'io'; 
}; 
return IO 
Post a Comment for "How Do I Return Eval(code) And Get An Object Back With Javascript?"