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

Rodrigo Carranza rodrigocarranza at outlook.com
Wed Nov 29 06:31:23 UTC 2017


________________________________

> 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<https://github.com/tc39/proposal-optional-chaining>
> into the object literal notation. I suggest using the same character pair, "?.", as is proposed for optional chaining, instead of just "?".
> ```js
> let ret = {
>     couldBeNull?.,
>     bar?.: couldBeNull
> }
> ```
>
> The helper function might be best in the case where an empty string value needs the same treatment as null or undefined.

That proposal is awesome, but I think the real operator here is the `?`, in combination with the chaining operator `?.` but it could be anything with the same semantics `?:` for objects `?.` for chaining `?=` for assignment `??` binary comparison. Just like in Dart but with extended functionality.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171129/f57700ba/attachment.html>


More information about the es-discuss mailing list