@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
50 lines (33 loc) • 1.45 kB
Markdown
---
lang: en
title: 'API docs: context.context._constructor_'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.context._constructor_.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[](./index.md) > [@loopback/context](./context.md) > [Context](./context.context.md) > [(constructor)](./context.context._constructor_.md)
Create a new context.
<b>Signature:</b>
```typescript
constructor(_parent?: Context | string, name?: string);
```
| Parameter | Type | Description |
| --- | --- | --- |
| \_parent | [Context](./context.context.md) \| string | The optional parent context |
| name | string | Name of the context. If not provided, a unique identifier will be generated as the name. |
```ts
// Create a new root context, let the framework to create a unique name
const rootCtx = new Context();
// Create a new child context inheriting bindings from `rootCtx`
const childCtx = new Context(rootCtx);
// Create another root context called "application"
const appCtx = new Context('application');
// Create a new child context called "request" and inheriting bindings
// from `appCtx`
const reqCtx = new Context(appCtx, 'request');
```