Default value of destructured { o, b, j, e, c, t } = {}

Bucaran jbucaran at
Fri Jul 10 03:25:23 UTC 2015

If the last argument to a function is a destructured object 
with at least one having a default value, makie it `{}` by default.

For example:

function doSomething ({ a: true }) {
doSomething({ a: false }) // OK
doSomething() // fails because the object is undefined

// solution
function doSomething ({ a: true } = {}) {

I find that for complex objects (such as options to methods), 
having to make the argument’s default value `{}` in every
function declaration inconvenient.

Let me know your feedback / comments.

Jorge Bucaran

More information about the es-discuss mailing list