I'd just like to suggest a couple FRs if possible, going or a hat trick here , to take advantage of built-in JS features for workflows with heavy use of functions (helps with code readability, maintainability, duplication and size):
Default Parameters
Workaround: currently I pass null
(or, in some instances I forget and ""
sneaks in there) as the parameter value. inside the function I check if each parameter is null/empty then set it to a default value if so).
Problem: lots of parameters. for every additional parameter we're requiring the equivalent of a validation check to do what JS does in the background, probably not a big deal unless you're using the function in a loop (in which case you now literally have an exponentially growing problem).
It's def personal preference here , but I'd rather have lots of parameters w default values than have to remember which of these functions is my entry point... mostly because I can't even remember to add 'entry_' to the function name in the first place so this might just be a 'me' problem
Rest Parameter
Huh?:
function addAllParameters(...args){
let sum = 0;
for (arg of args) sum += arg;
return sum;
}
addAllParameters(1, 2, 3, 4, 5, 6, 7); // valid
addAllParameters(9, 10); //valid
Workaround: using lots of parameters, which now sounds like a catch 22 after the above
Problem: functions with unknown number of parameters either can't be done or have to have custom limits, requiring more code.
JS Function Arguments Object
Huh?:
function sumAll() {
let sum = 0;
for (let i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
}
This is actually just another way to support an unknown number of parameters, it's just less common because of how deceiving it can be to anyone who didn't directly write the function or didn't read the docs or function header... it's an object though so I'd assume it'd be easier to pass the object reference around so we have access to it than supporting the rest param ...
?
actually just realized if you could add the dynamic/fx
button thingy to toggle between 2 inputs for key/value and 1 text input for something like {{ ...args }}
it might be easier than the arguments obj