Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node.js vm

const vm = require('vm');

const x = 1;

const context = { x: 2 };
vm.createContext(context); // Contextify the object.

const code = 'x += 40; var y = 17;';
// `x` and `y` are global variables in the context.
// Initially, x has the value 2 because that is the value of context.x.
vm.runInContext(code, context);

console.log(context.x); // 42
console.log(context.y); // 17

console.log(x); // 1; y is not defined.
Comment

PREVIOUS NEXT
Code Example
Javascript :: SyntaxError: Unexpected token F in JSON at position 0 
Javascript :: react native image picker 
Javascript :: get html 
Javascript :: javascript map method 
Javascript :: javascript document 
Javascript :: base64 to base64url javascript 
Javascript :: react native basic template 
Javascript :: new date javascript 
Javascript :: jquery basics 
Javascript :: javascript create array 
Javascript :: javascript Program to check if a given year is leap year 
Javascript :: component will mount hooks 
Javascript :: parsley custom error message 
Javascript :: replace spaces with dashes 
Javascript :: how to change textContent in js 
Javascript :: html-pdf nodejs 
Javascript :: how to make a syntax highlighter in javascript 
Javascript :: How to make a toggle button in Angularjs 
Javascript :: delete value from an array javascript 
Javascript :: reverse an array 
Javascript :: .then function 
Javascript :: object object js 
Javascript :: lodash template literal 
Javascript :: could not find react-redux context value; please ensure the component is wrapped in a <Provider 
Javascript :: json.stringify file object return {} 
Javascript :: react admin data provider 
Javascript :: launch json 
Javascript :: sign javascript 
Javascript :: jq json 
Javascript :: prototype example 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =