Created
December 28, 2016 20:48
-
-
Save AnnaMag/6d79a9d493181e1942a1cbe7a2c3e9f5 to your computer and use it in GitHub Desktop.
Node.js doc: Outside of scripts run by the vm module, "global variables" will remain unchanged.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const util = require('util'); | |
const vm = require('vm'); | |
var globalVar = 3; | |
const sandbox = { globalVar: 1 }; | |
vm.createContext(sandbox); | |
vm.runInContext('globalVar *= 2;', sandbox); | |
console.log(util.inspect(sandbox)); // 2 | |
console.log(util.inspect(globalVar)); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment