javascript - Node VM - Return an object implicitly -


i looking way simple scripting in node js , discovered vm module. documentation specifies run* methods return result of execution, thought "hey, why not return object way , call on properties in main script?"

so fire node repl:

$ node > var vm = require('vm'); undefined > vm.runinnewcontext("{ foo: 'bar' }") 'bar' > vm.runinnewcontext("{ foo: 'bar', baz: 'qux' }") evalmachine.<anonymous>:1 { foo: 'bar', baz: 'qux' }                  ^ syntaxerror: unexpected token : > 

not quite expected results. interestingly, if return result of assignment...

> vm.runinnewcontext("exports = { foo: 'bar', baz: 'qux' }") { foo: 'bar', baz: 'qux' } 

can explain behavior me?

v8 interpreting braces code block containing labels. wrap in parentheses: vm.runinnewcontext("({foo: 'bar', baz: 'qux'})").


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -