A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
A way to prevent properties to be added to an object if they are null or undefined. Currently this can be accomplished in many ways: With an if: ```js function foo(couldBeNull){ let ret = {} if(couldBeNull){ ret.couldBeNull = couldBeNull } return ret } ``` With ternary (kind of gross) ```js

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Sebastian Malton
properties to be added to an object if they are null or undefined. A way to prevent properties to be added to an object if they are null or undefined. Currently this can be accomplished in many ways: With an if: ```js function foo(couldBeNull){ let ret = {} if(couldBeNull){ ret.couldBeNull

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
added to an object if they are null or undefined. A way to prevent properties to be added to an object if they are null or undefined. Currently this can be accomplished in many ways: With an if: ```js function foo(couldBeNull){ let ret = {} if(couldBeNull){ ret.couldBeNull<http://ret.cou

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Sebastian Malton
@mozilla.orgSubject: Re: A way to prevent properties to be added to an object if they are null or undefined. It's about the value of the property to be added, nothing to do with the name of the property. It should discard properties whose value are null(but this behavior is not always desired,

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Michał Wadas
You can just use proxy with proper set trap. On Wed, 29 Nov 2017 at 02:30, Rodrigo Carranza wrote: > A way to prevent properties to be added to an object if they are null or > undefined. > > Currently this can be accomplished in many ways: > > With an if: > ```js >

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread J Decker
carra...@outlook.com> wrote: > >> A way to prevent properties to be added to an object if they are null or >> undefined. >> >> Currently this can be accomplished in many ways: >> >> With an if: >> ```js >> function foo(couldBeNull){ >>

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Bob Myers
; > On Tue, Nov 28, 2017 at 5:50 PM, Michał Wadas > wrote: > >> You can just use proxy with proper set trap. >> >> On Wed, 29 Nov 2017 at 02:30, Rodrigo Carranza < >> rodrigocarra...@outlook.com> wrote: >> >>> A way to prevent properties

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
: rodrigocarra...@outlook.com Sent: November 28, 2017 8:40 PM To: sebast...@malton.name Cc: es-discuss@mozilla.org Subject: Re: A way to prevent properties to be added to an object if they are null or undefined. It's about the value of the property to be added, nothing to do with the name of the pro

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
: rodrigocarra...@outlook.com Sent: November 28, 2017 8:40 PM To: sebast...@malton.name Cc: es-discuss@mozilla.org Subject: Re: A way to prevent properties to be added to an object if they are null or undefined. It's about the value of the property to be added, nothing to do with the name of the pro

RE: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
2017 at 02:30, Rodrigo Carranza mailto:rodrigocarra...@outlook.com>> wrote: A way to prevent properties to be added to an object if they are null or undefined. Currently this can be accomplished in many ways: With an if: ```js function foo(couldBeNull){ let ret = {} if(couldBeNull){ ret.co

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread kai zhu
so I'm new to mailing lists. > > ________________ > De: J Decker > Enviado: martes, 28 de noviembre de 2017 09:07 p.m. > Para: Michał Wadas > Cc: Rodrigo Carranza; es-discuss@mozilla.org > Asunto: Re: A way to prevent properties to be added to an object

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Jerry Schulteis
I was about to hit send on a post also suggesting a helper function, but after thinking about it a bit more, Rodrigo's suggestion resembles extending the optional chaining proposal https://github.com/tc39/proposal-optional-chaining into the object literal notation. I suggest using the same chara

RE: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
b.collection('Posts').find({ categoryId?, postType? }) } ``` De: kai zhu Enviado: martes, 28 de noviembre de 2017 11:43 p.m. Para: Rodrigo Carranza Cc: J Decker; Michał Wadas; es-discuss@mozilla.org Asunto: Re: A way to prevent properties to be added to an object if they are null or

RE: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Rodrigo Carranza
> I was about to hit send on a post also suggesting a helper function, but > after thinking about it a bit more, Rodrigo's suggestion resembles extending > the optional chaining proposal > https://github.com/tc39/proposal-optional-chaining

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-11-28 Thread Naveen Chawla
What is the end goal of this proposal? To reduce the size of a serialized JSON? I can't see any other use for it. If that's the case, then perhaps a stringify that skips undefineds and nulls is more appropriate. Otherwise, what is the purpose / example case where this would be useful? On Wed, 29 N

Re: A way to prevent properties to be added to an object if they are null or undefined.

2017-12-02 Thread Naveen Chawla
miércoles, 29 de noviembre de 2017 1:54 > *Para:* Rodrigo Carranza > *CC:* jdschult...@yahoo.com; es-discuss@mozilla.org > > > *Asunto:* Re: A way to prevent properties to be added to an object if > they are null or undefined. > > > > What is the end goal of this propo

Re: Re%3A A way to prevent properties to be added to an object if they are null or undefined.&In-Reply-To=

2017-11-28 Thread 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 prop

Re: Re%3A A way to prevent properties to be added to an object if they are null or undefined.&In-Reply-To=

2017-11-28 Thread 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, s