Return a small object that groups behavior with captured settings.

factory-namespace A factory can build a tiny namespace with methods that share settings. The returned object is used immediately here so replay stays focused on scalar results.

Factory Namespace

step
factory_namespace.js
Replay: real traced execution (multi-file project)
const step = 2;
function makeCounter(increment) {
  return {
    next(value) {
      return value + increment;
    },
  };
}

const nextValue = makeCounter(step).next(10);

console.log("step=" + step);
console.log("next=" + nextValue);
const step = 4;
function makeCounter(increment) {
  return {
    next(value) {
      return value + increment;
    },
  };
}

const nextValue = makeCounter(step).next(10);

console.log("step=" + step);
console.log("next=" + nextValue);
const step = 6;
function makeCounter(increment) {
  return {
    next(value) {
      return value + increment;
    },
  };
}

const nextValue = makeCounter(step).next(10);

console.log("step=" + step);
console.log("next=" + nextValue);
  1. step ← 2

    1const step→ 2 = 2; //@step=4, 62function makeCounter(increment) {3  return {4    next(value) {5      return value + increment;6    },7  };8}910const nextValue = makeCounter(step2).next(10);
  2. //@step=4, 6 function makeCounter(increment)

    1const step = 2; //@step=4, 62function makeCounter(increment2) {3  return {4    next(value) {5      return value + increment;6    },7  };8}
  3. nextValue ← 12

    7  };8}910const nextValue→ 12 = makeCounter(step2).next(10);1112console.log("step=" + step2);13console.log("next=" + nextValue12);
    outputstep=2
    next=12
  1. step ← 4

    1const step→ 4 = 4;2function makeCounter(increment) {3  return {4    next(value) {5      return value + increment;6    },7  };8}910const nextValue = makeCounter(step4).next(10);
  2. function makeCounter(increment)

    1const step = 4;2function makeCounter(increment4) {3  return {4    next(value) {5      return value + increment;6    },7  };8}
  3. nextValue ← 14

    7  };8}910const nextValue→ 14 = makeCounter(step4).next(10);1112console.log("step=" + step4);13console.log("next=" + nextValue14);
    outputstep=4
    next=14
  1. step ← 6

    1const step→ 6 = 6;2function makeCounter(increment) {3  return {4    next(value) {5      return value + increment;6    },7  };8}910const nextValue = makeCounter(step6).next(10);
  2. function makeCounter(increment)

    1const step = 6;2function makeCounter(increment6) {3  return {4    next(value) {5      return value + increment;6    },7  };8}
  3. nextValue ← 16

    7  };8}910const nextValue→ 16 = makeCounter(step6).next(10);1112console.log("step=" + step6);13console.log("next=" + nextValue16);
    outputstep=6
    next=16