UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

95 lines (51 loc) 1.75 kB
--- 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. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Context](./context.context.md) &gt; [(constructor)](./context.context._constructor_.md) ## Context.(constructor) Create a new context. **Signature:** ```typescript constructor(_parent?: Context | string, name?: string); ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> \_parent </td><td markdown="1"> [Context](./context.context.md) \| string </td><td markdown="1"> _(Optional)_ The optional parent context </td></tr> <tr><td markdown="1"> name </td><td markdown="1"> string </td><td markdown="1"> _(Optional)_ Name of the context. If not provided, a unique identifier will be generated as the name. </td></tr> </tbody></table> ## Example ```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'); ```