Hint
Fluent/builder pattern: returning this from methods enables chaining. Each call in the chain gets the same object as this.
class Builder {
constructor() { this.parts = []; }
add(part) {
this.parts.push(part);
return this; // enables chaining
}
build() {
return this.parts.join(' + ');
}
}
const result = new Builder()
.add('A')
.add('B')
.add('C')
.build();
console.log(result);A + B + C
Explanation: Each .add() returns this (the Builder instance), so the next call still has the same this. .build() reads this.parts which has accumulated all three parts.
Key Insight: Fluent/builder pattern: returning this from methods enables chaining. Each call in the chain gets the same object as this.