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:
functiondoSomething ({ a: true }) {
console.log(a)
}
doSomething({ a: false }) // OK
doSomething() // fails because the object is undefined// solutionfunctiondoSomething ({ 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.
Jorge Bucaran
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
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 }) { 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.
Jorge Bucaran