Re: Re%3A A way to prevent properties to be added to an object if they are null or undefined.&In-Reply-To=<CABOscaYZcYD%2BFqp6pyNB6%3D908xfObLznsovXavQg58sL%2B%3Dx%2BXg%40mail.gmail.com>

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Re%3A A way to prevent properties to be added to an object if they are null or undefined.&In-Reply-To=<CABOscaYZcYD%2BFqp6pyNB6%3D908xfObLznsovXavQg58sL%2B%3Dx%2BXg%40mail.gmail.com>

Rodrigo Carranza
Yeah, it was wrong, I'm currently using like

```js
let ret = { ... ( couldBeNull ? {couldBeNull} : {} ) }
```

Yours is better and the usual idiom a bit hard to understand.

What I'm proposing is something like this

```js
let ret = { couldBeNull? }
```
or if you want a different name for the property

```js
let ret = { bar ?: couldBeNull }
```

It is not like there is no way to do this, there are plenty. But this way could make code a bit easier to read.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re%3A A way to prevent properties to be added to an object if they are null or undefined.&In-Reply-To=<CABOscaYZcYD%2BFqp6pyNB6%3D908xfObLznsovXavQg58sL%2B%3Dx%2BXg%40mail.gmail.com>

Naveen Chawla
What's the end goal? To reduce the size of a serialized JSON? Maybe a stringify that removes nulls and undefineds would be more suited if so. If not, I can't see what your end goal could be (can't be for iteration over an object, since that would also require a defined check to handle both cases, so no gain)?

On Wed, 29 Nov 2017 at 08:43 Rodrigo Carranza <[hidden email]> wrote:
Yeah, it was wrong, I'm currently using like

```js
let ret = { ... ( couldBeNull ? {couldBeNull} : {} ) }
```

Yours is better and the usual idiom a bit hard to understand.

What I'm proposing is something like this

```js
let ret = { couldBeNull? }
```
or if you want a different name for the property

```js
let ret = { bar ?: couldBeNull }
```

It is not like there is no way to do this, there are plenty. But this way could make code a bit easier to read.
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss