I have 2 functions with the same logic (eg: printing in console multiple concatenated elements) but with one specificity. The easy way is to specify the specificity in parameter, like this :
function baseLogic (specific, general) {
// ... many processes before here
if(specific == "info") console.info(general)
if(specific == "warn") console.warn(general)
}
// Calls
baseLogic("info", "foo")
baseLogic("warn", "bar")
However, i would like to handle this specificity with a function, not as a parameter, like this :
function baseLogic (specific, general) {
// ... many processes before here
if(specific == "info") console.info(general)
if(specific == "warn") console.warn(general)
}
function info(general) {
baseLogic("info", general)
}
function warn(general) {
baseLogic("warn", general)
}
// Calls
info("foo")
warn("foo")
Problem is, when i want to add/remove a parameter, for example, i need to add/remove it everywhere
Is there any way to do it better ?
Something like this :
function baseLogic (specific, general) {
// ... many processes before here
if(specific == "info") console.info(general)
if(specific == "warn") console.warn(general)
}
info = baseLogic("info")
warn = baseLogic("warn")
// Calls
info("foo")
warn("bar")
Thanks in advance !
aandbfunctions dynamically?