javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Store configuration in function default parameters

Open Jabher opened this issue 10 years ago • 1 comments

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.

Jabher avatar May 19 '15 19:05 Jabher

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.

ljharb avatar Dec 23 '15 19:12 ljharb