Optional named arguments

Forbes Lindesay forbes at lindesay.co.uk
Fri Aug 23 06:12:19 PDT 2013

The `=` operator in the object declaration is defining defaults for the destructuring.  If the object being destructured doesn't have that property, the value on the right hand side of the `=` operator is used.

The `= {}` provides a default object to de-structure, making the entire argument optional.  Without that you would be trying to de-structure `undefined` when you call `postToMailingList()` which would be an error.

If you don't pass an object, `{}` is used because it is the default.  If you pass an empty object then that empty object is used (i.e. still `{}`).

P.S. please just inline your code samples and use something like GitHub flavoured markdown to format your posts (i.e. code blocks begin and end with three back-tick characters)  That way they will be quick and easy to read on http://esdiscuss.org/topic/optional-named-arguments  You can see plenty of examples by clicking on "View Original" (e.g. I re-formatted your last post for you)

More information about the es-discuss mailing list