Constructor
new Scope(parent, name, children)
Constructs a new Scope instance representing a node in a tree structure.
Parameters:
Name | Type | Description |
---|---|---|
parent |
Scope | undefined | (Optional) The parent Scope, establishing upward linkage in the tree. |
name |
string | undefined | (Optional) The name assigned to this Scope, typically within its parent's children map. |
children |
Object.<string, Scope> | (Optional) A dictionary of named child Scopes. Each Scope can hold arbitrary properties and may reference children and a parent, enabling hierarchical navigation and scoped resolution of values. |
Example
const root = new Scope();
const child = new Scope();
root.letChild('child1', child);
Classes
Members
name
Gets the name of this Scope.
parent
Gets the parent Scope.
parent
Sets the parent Scope.
Methods
ancestors() → {Each}
Returns an Each instance that iterates over this Scope and its ancestors.
Returns:
- Type
- Each
children() → {Each}
Returns an Each instance over this Scope's children.
Returns:
- Type
- Each
forget(name) → {Scope}
Removes a property from the Scope.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Property name |
Returns:
- The Scope itself (for chaining)
- Type
- Scope
get(…names) → {*}
Retrieves a property by name by searching up through ancestors.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
names |
string |
<repeatable> |
Property name(s) |
Returns:
- The first matching property value found
- Type
- *
getChild(…names) → {Scope|undefined}
Retrieves a nested child Scope by following the given path of names.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
names |
string |
<repeatable> |
Path of child names |
Returns:
- The resolved child Scope or undefined
- Type
- Scope | undefined
isLeaf() → {boolean}
Checks if the Scope has no children.
Returns:
- Type
- boolean
isRoot() → {boolean}
Checks if this Scope is the root (has no parent).
Returns:
- Type
- boolean
let(name, value) → {Scope}
Stores a named property in this Scope.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Property name |
value |
* | Value to store |
Returns:
- The Scope itself (for chaining)
- Type
- Scope
letChild(name, child) → {Scope}
Adds a child Scope under this Scope.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Name of the child |
child |
Scope | The child Scope |
Returns:
- The Scope itself (for chaining)
- Type
- Scope
resolve(nameOrObj) → {*}
Resolves a value or a named reference in the scope.
Parameters:
Name | Type | Description |
---|---|---|
nameOrObj |
string | * | Name or value |
Returns:
- Resolved value
- Type
- *
root() → {Scope}
Recursively finds the root Scope.
Returns:
- Type
- Scope