Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

runincontext execute function

var vm = require('vm');

function myfn() {
    console.log("MYFN");
    console.log("MYFN: a="+ a);
}


var sandbox={console:console, a:42};
var ctx = new vm.createContext(sandbox);

// Evaluates the source code of myfn in the new context
// This will ensure that myfn uses the global context of 'ctx'
vm.runInContext(myfn.toString(), ctx, {filename: "TEST"});

// Retained in the context
console.log(ctx.myfn);

// Use it
vm.runInContext("function okfn() { console.log('OKFN'); console.log('OKFN: a='+a); } console.log('TEST'); console.log('TEST: a='+a);okfn();  myfn();", ctx, {filename:"TEST"});
Comment

PREVIOUS NEXT
Code Example
Javascript :: callbacks 
Javascript :: javascrip loop array 
Javascript :: { "name":"walk dog", "isComplete":true } 
Javascript :: append dynamica html in jsx react 
Javascript :: isempty is not a function javascript 
Javascript :: midpointrounding.awayfromzero javascript 
Javascript :: 10.3.1. Function Syntax 
Javascript :: react native undedined map 
Javascript :: cproblem upgrading node on windws 
Javascript :: javascript debugging methods 
Javascript :: %20find%20all%20docs%20that%20have%20at%20least%20two%20name%20array%20elements_ 
Javascript :: get keyword in javascript 
Javascript :: jquery to json diff 
Javascript :: use chai immutable 
Javascript :: how to use variable key as dictionary key in javascript 
Javascript :: app scrip sheet cell boarder 
Javascript :: micromodal scrolls to bottom 
Javascript :: global variables using strict mode 
Javascript :: fat arrow return object 
Javascript :: blabla 
Javascript :: if element touches another element on scroll 
Javascript :: firestorage vuetify 
Javascript :: javascript bitset 
Javascript :: set value localstorage javascript 
Javascript :: notion value of empte date property 
Javascript :: how to stop component to render multiple time 
Javascript :: como saber si un afecha es mayor o menor js 
Javascript :: jest check the link of a button 
Javascript :: Angular bind only when mouse moves 
Javascript :: image uploading payload 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =