Node.js VM Module
ဥပမာ
"virtual machine" တွင် JavaScript ကုဒ်အချို့ကိုဖွင့်ပါ-
var vm = require('vm');
var myObj = { name: 'John', age: 38 };
vm.createContext(myObj);
vm.runInContext('age += 1;', myObj);
console.log(myObj);
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
VM module သည် JavaScript ရှိ eval() ကဲ့သို့ virtual machine တစ်ခုပေါ်တွင် JavaScript ကိုလုပ်ဆောင်သည့်နည်းလမ်းကို ပံ့ပိုးပေးပါသည်။
အထားအသို
သင့်အပလီကေးရှင်းတွင် VM module အပါအဝင် အထားအသို-
var vm = require('vm');
VM Properties နှင့် Methods
Method | Description |
---|---|
createContext() | Prepares a virtual machine, or sandbox, where you can execute scripts |
isContext() | Returns true if the specified sandbox has been created by the createContext() method |
runInContext() | Executes JavaScript code in the specified context, and returns the result |
runInDebug() | Executes JavaScript inside the debug context |
runInNewContext() | Executes JavaScript code in a new context, and returns the result |
runInThisContext() | Executes JavaScript code in the global context, and returns the result |