@loopback/docs
Version:
Documentation for LoopBack 4
50 lines (32 loc) • 1.35 kB
Markdown
---
lang: en
title: 'API docs: context.context.(constructor)'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
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 | <code>Context &
| name | <code>string</code> | Name of the context, if not provided, a <code>uuid</code> 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');
```