How do I return the last value from the new Function() constructor? Seems eval() does this by default, as well as vm.Script#runInContext.
I just want to create a REPL in the browser (where I can do something like 2+2; and it returns 4 in the output) like eval, but without the drawbacks of eval (local function scope access, AsyncFunction, etc...)
There is no way to do this.
new Function()does not provide any way to access the "Completion Records" of it's invocation, according to the ECMAScript specification part on Function objects.So if you need the last value, you have to use
eval()