Skip to main content

globalThis

Each script operates in its own isolated environment, but they can share data via a common globalThis object.

At the start of a script, it initializes by reading the globalThis from the current request's context. When the script concludes, it stores the updated globalThis back into the context for future reference.

Example

Script 1 initialization

script-1
globalThis = { name: "luwak", age: 1 }

Script 2 modification

script-2
globalThis.age = 2;

globalThis.description = "database middleware";

Script 3 final result

script-3
luwak.returnResult(globalThis);

Return results

json
{
"name": "luwak",
"age": 2,
"description": "database middleware"
}