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

Bucaran jbucaran at me.com
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:

```js
function doSomething ({ a: true }) {
  console.log(a)
}
doSomething({ a: false }) // OK
doSomething() // fails because the object is undefined

// solution
function doSomething ({ a: true } = {}) {
  console.log(a)
}
```

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.

Regards
Jorge Bucaran


More information about the es-discuss mailing list