I don't use `in`.

What do I get with `'x' !in obj` or `!(x in obj)` that I don't get with
!obj['x'] ?

Genuinely asking - I don't know what I am missing.

I use obj[x] because I believe it's a more familiar syntax and I believe I
get the same outcome..(?)..

On Mon, 9 Jul 2018 at 22:41 Steve Fink <sph...@gmail.com> wrote:

> +1 from me for !in. It's a surprisingly common nuisance.
>
> And I don't care for the !obj.x workaround at all -- even if you can
> survive the difference in semantics, from a code reading point of view this
> is saying something entirely different.
>
> And it is very different semantically. 'x' in obj does [[HasProperty]];
> obj.x does [[GetProperty]]. With
>
>   obj = { get x() { print("getter"); return 3; } };
>
> then |"x" in obj| does not print "getter" while |obj.x| does.
>
>
> On 06/29/2018 12:26 AM, Cyril Auburtin wrote:
>
>
> ```js
> if (!obj.x && !obj.y) {
>      doit()
> }
> ```
> The cases where they are equal to 0, '', null, undefined shouldn't matter
> imo, if for example those x and y are numbers, they would be defined,
> defaulted to 0, and you would test for `!== 0` rather if needed
>
> Le jeu. 28 juin 2018 à 18:31, Guylian Cox <guylian...@gmail.com> a écrit :
>
>> I agree, it's very annoying to have to write it !(x in y). I've been
>> wanting this operator for a very, very long time.
>>
>> If there is interest for !in, I think !instanceof deserves to be
>> included too.
>>
>> Le jeu. 28 juin 2018 à 18:19, T.J. Crowder <
>> tj.crow...@farsightsoftware.com> a écrit :
>>
>>> On Thu, Jun 28, 2018 at 5:14 PM, Tobias Buschor <
>>> tobias.busc...@shwups.ch> wrote:
>>> > I dont like to write:
>>> > if ( !('x' in obj) &&  !('y' in obj) ) {
>>> >      doit()
>>> > }
>>> >
>>> > I was even tempted to write it that way:
>>> > if ('x' in obj  ||  'y' in obj) { } else {
>>> >      doit()
>>> > }
>>>
>>> There's
>>>
>>> ```js
>>> if (!('x' in obj  ||  'y' in obj)) {
>>>      doit()
>>> }
>>> ```
>>>
>>> That said, I've wanted !in many a time, in a minor sort of way...
>>>
>>> -- T.J. Crowder
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss@mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing 
> listes-discuss@mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to