1. You have classes but you do not effectively need them because they do not keep any state (even the applied
field is actually unused). In C# you do not have much options (unless they're local) but in JavaScript you can use functions anywhere:
2. In short, your code might be:
3. To answer the question about "do you need a class for Producer
?": if you don't need to call produce()
multiple times on the same object then you don't even need a class and everything may be reduced to:
4. If you're using a class only to give a chance to the caller to specify a different set of rules:
produce(starterString, rules = [ ruleAddE, ruleAddNumberOne ]) {
return rules.reduce((text, rule) => rule(text), starterString || "");
}