main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
890 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.default = void 0;
|
---|
5 | class Node {
|
---|
6 | static type = 'node';
|
---|
7 | type = 'node';
|
---|
8 | isMissing;
|
---|
9 | children;
|
---|
10 | position;
|
---|
11 | constructor({
|
---|
12 | children = [],
|
---|
13 | position,
|
---|
14 | isMissing = false
|
---|
15 | } = {}) {
|
---|
16 | this.type = this.constructor.type;
|
---|
17 | this.isMissing = isMissing;
|
---|
18 | this.children = children;
|
---|
19 | this.position = position;
|
---|
20 | }
|
---|
21 |
|
---|
22 | // creates shallow clone of node
|
---|
23 | clone() {
|
---|
24 | // 1. copy has same prototype as orig
|
---|
25 | const copy = Object.create(Object.getPrototypeOf(this));
|
---|
26 |
|
---|
27 | // 2. copy has all of orig’s properties
|
---|
28 | Object.getOwnPropertyNames(this) // (1)
|
---|
29 | .forEach(propKey => {
|
---|
30 | // (2)
|
---|
31 | const descriptor = Object.getOwnPropertyDescriptor(this, propKey); // (3)
|
---|
32 | // @ts-ignore
|
---|
33 | Object.defineProperty(copy, propKey, descriptor); // (4)
|
---|
34 | });
|
---|
35 | return copy;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | var _default = exports.default = Node; |
---|
Note:
See
TracBrowser
for help on using the repository browser.