Skip to main content
Script.prototype.runInThisContext - node__vm.d.ts - Node documentation
method Script.prototype.runInThisContext

Usage in Deno

```typescript import { Script } from "node:node__vm.d.ts"; ```
Script.prototype.runInThisContext(options?: RunningScriptOptions): any
Runs the compiled code contained by the `vm.Script` within the context of the current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object. The following example compiles code that increments a `global` variable then executes that code multiple times: ```js import vm from 'node:vm'; global.globalVar = 0; const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' }); for (let i = 0; i < 1000; ++i) { script.runInThisContext(); } console.log(globalVar); // 1000 ```

Parameters

optional
options: RunningScriptOptions

Return Type

any
the result of the very last statement executed in the script.