html
html
1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Nested Recursive Objects & Arrays</title>
</head>
<body>
See JS Console Ouput
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// My intention is to create a single “template” object definition that can be used to build a tree of spine / leaves of the same object.
// Also functions are created that can get/set values of any properties for any leaf using an array representing the position of the leaf in the tree.
// Create Spine/Leaf Object Template
class objTemplate {
constructor(SpineName, Width, Height) {
this.SpineName = SpineName;
this.Width = Width;
this.Height = Height;
this.Leaves = [];
}
get SpineName() {
return this._SpineName;
}
set SpineName(value) {
if (value.length === 0) {
console.log("Spine Name Is Required.");
throw new Error("Spine Name Is Required.");
}
this._SpineName = value;
}
get Width() {
return this._Width;
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run