javascript
javascript copied to clipboard
Store configuration in function default parameters
E.g.
function call(url, timeout = 60) {
return request.call(url, {timeout});
}
I think that really makes sense. Moreover, that's a JavaScript way - "everything is exposed, except what's hidden explicitly".
I've been using this technique for a long time and it really makes sense, as it's rather common situation — when you suddenly find out you need to override some closure-stored configuration variables during the call.
I'm concerned about this approach, primarily because if you later need to add a required argument, it becomes a breaking change (because somebody might have relied on the timeout value). However, I also am not in favor of exposing anything publicly when it's not strictly necessary.