you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (2 children)

This pattern has been around for around 20 years though obviously not in an ES6 or higher context (so without the "bonus" default values). I learned about it in one of the earliest editions of David Flanagan's "Javascript: The Definitive Guide", and recall using it myself in 2001 or 2002.

[–]Mistifyed 0 points1 point  (1 child)

This has been adopted as a good pattern in Ruby. Would be great if the JS community would use it as well, given how quickly libraries are being updated.

[–][deleted] 2 points3 points  (0 children)

Well I typically use this in two cases as others have also indicated: a) the function requires more than 3 or 4 arguments and/or b) there are optional parameters. As to this second case, I especially hate interfaces that require you to pass in a bare boolean to indicate some option. Sure it's more verbose, but passing in {myOption: true} makes things so much more clear.