If I have this code:
function Person(name) {
this.name = name;
}
Person.prototype.say = function () {
console.log(this.name + "Preset");
};
How would be the most appropriate way to make "Preset"
easily configurable? In this example, it's not hard at all. You just change it. But suppose that's in a cluster of other methods and even this very method contains lots of code both before and after the preset. It would be hard, especially if I have several presets that modify the outcome of a common task. I would have to search through all the code like crazy.
What should I do if I have multiple classes with multiple presets? Should I make an object with the presets before declaring each class and then use it inside the declaration? Should I make a presets file with all the presets? If I should make a file, how could I get the preset values without an excessively long line of code like:
Person.prototype.say = function () {
console.log(this.name + MyNamespace.Presets.Person.var1, 500, MyNamespace.Presets.General.something, MyNamespace.Presets.Foo.bar);
};
Finally, if I have a preset that's being used by several classes, where should I store that?
Is there a convention or a pattern for those things?
If that's the wrong stack for this question, please tell me where it's appropriate to ask.
Aucun commentaire:
Enregistrer un commentaire