Last active
August 29, 2015 14:02
-
-
Save danmactough/43c5fb61fadf9c7df5ad to your computer and use it in GitHub Desktop.
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
var vm = require('vm'); | |
var boss = 'Mr. Trump' | |
, condition = 'bald'; | |
var script = [ | |
'boss = name;', | |
'condition = type;', | |
'result = boss + " is " + condition;' | |
].join('\n'); | |
var ctx = { | |
name: 'Dan', | |
type: 'awesome' | |
}; | |
var evaled = vm.runInContext(script, vm.createContext(ctx)); | |
console.log(evaled); | |
// Dan is awesome | |
ctx = { | |
name: boss, | |
type: condition | |
}; | |
var evaled = vm.runInContext(script, vm.createContext(ctx)); | |
console.log(evaled); | |
// Mr. Trump is bald |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment