Modules and Namespaces
Nested Namespace
Use a nested namespace for a smaller group of operations.
nested-namespace
Nested namespaces can separate groups inside a larger API. Keep the hierarchy small so the call path remains easy to read.
Nested Namespace
nested_namespace.js
Replay: real traced execution (multi-file project)
const base = 3;
const label = {
math: {
double(value) {
return value * 2;
},
},
}.math.double(base);
console.log("base=" + base);
console.log("label=" + label);
const base = 5;
const label = {
math: {
double(value) {
return value * 2;
},
},
}.math.double(base);
console.log("base=" + base);
console.log("label=" + label);
const base = 8;
const label = {
math: {
double(value) {
return value * 2;
},
},
}.math.double(base);
console.log("base=" + base);
console.log("label=" + label);
base ← 3, label ← 6
1const base→ 3 = 3; //@base=5, 82const label→ 6 = {3 math: {4 double(value) {5 return value * 2;6 },7 },8}.math.double(base3);910console.log("base=" + base3);11console.log("label=" + label6);outputbase=3 label=6values this step[object Object]{ math: { double(value) { return value * 2; }, }, }.math
base ← 5, label ← 10
1const base→ 5 = 5;2const label→ 10 = {3 math: {4 double(value) {5 return value * 2;6 },7 },8}.math.double(base5);910console.log("base=" + base5);11console.log("label=" + label10);outputbase=5 label=10values this step[object Object]{ math: { double(value) { return value * 2; }, }, }.math
base ← 8, label ← 16
1const base→ 8 = 8;2const label→ 16 = {3 math: {4 double(value) {5 return value * 2;6 },7 },8}.math.double(base8);910console.log("base=" + base8);11console.log("label=" + label16);outputbase=8 label=16values this step[object Object]{ math: { double(value) { return value * 2; }, }, }.math