# ContextVar

`import { ContextVar } from "destack:context";`

One dynamically scoped execution value.

```ds title="ContextVar"
export class ContextVar<T: Copy> {
    name: string;
    defaultValue: T;
    constructor(name: string, defaultValue: T);
    get(): T;
    run<R>(value: T, body: () => R): R;
}
```

[language/library/src/context/variable.ds:7:31](https://github.com/destack-sh/destack/blob/main/language/library/src/context/variable.ds#L7-L31)

## Members

### `name: string`

Diagnostic name.

### `defaultValue: T`

Value outside an overriding scope.

### `constructor(name: string, defaultValue: T)`

Create one context variable.

### `get(): T`

Return the current value.

### `run<R>(value: T, body: () => R): R`

Run `body` with `value` bound to this variable.
