I actually don't think this is worth pursuing, as it can easily be implemented
by libraries once we solve operator overloading, without adding new syntax:

``
  if (1 < [2, 3])
``

Am 01.02.2017 um 18:12 schrieb Ryan Birmingham:
I have a handfull of questions on this proposal as well:
How would your proposal look with three or four things to check against? Would the collection of things to check against be a variable? Would this be syntactic sugar to the array includes method, or would this be something entirely new?

-Ryan Birmingham

On 1 February 2017 at 12:03, Felipe Nascimento de Moura <[email protected] <mailto:[email protected]>> wrote:

    I see...
    we could perhaps think on some other approach.

    What about:
    if (obj.prop.prop ?== 'a' : 'b')

    This way, we have "?==", which is not too chocking once we already
    got "!==", and this kinda prepares the engine to deal with the
    next values as part of the comparison.
    Also, feels familiar due to " something ? 'a' : 'b' "

    Personally, I don't feel that comfortable with this syntax.
    We could think on different a token as well

    if (obj.prop.prop === (? 'a' : 'b')) // feels like a ternary, but
    without the first statement
    if (obj.prop.prop === ('a'  | 'b'))) // could break the web once
    it is already valid syntax (although not very used)
    if (obj.prop.prop === ('a' :: 'b')) // perhaps a double colon

    Anyways, open for suggestions :)




    On Wed, Feb 1, 2017 at 2:48 PM Ryan Birmingham
    <[email protected] <mailto:[email protected]>> wrote:

        I like the idea, and I generally agree that your proposal
        would increase readability, but I'm not a fan of the colon in
        parenthesis.
        In this context, the colon looks like it should represent a
        member assignment of 'b' to 'a'.


        -Ryan Birmingham

        On 1 February 2017 at 11:27, Felipe Nascimento de Moura
        <[email protected] <mailto:[email protected]>> wrote:

            Hi.

            I wonder if there is already a proposal for such thing or
            if it would be something interesting to be proposal:

            *The motivation:*
            Let's say you have an object whose property you want to
            compare to 'a' or 'b':

            ```
            if (object.property.secondProp === 'a' ||
            object.property.secondProp === 'b') {
              // do something
            }
            ```

            *The proposal:*
            Now, with this syntax you would be able to perform such
            comparisons in a much simpler, better to read approach:

            ```
            if (object.property.secondProp === ('a' : 'b')) {
                // do Something
            }
            ```

            And with the advance of the Optional Chaining Operator
            <https://github.com/claudepache/es-optional-chaining> proposal,
            it would get even better, like so:

            ```
            // this:
            if (object &&
            object.property &&
            (object.property.secondProp === 'a' ||
            object.property.secondProp === 'b')) {
              // ...
            }

            // becomes this:
            if (object?.property?.secondProp === ('a' : 'b')) { ... }
            ```

            *Alternatives:*
            I do know that we could accomplish that with other
            techniques, like:

            ```
            ['a', 'b'].includes(object.property.secondProp)
            ```

            I just think it might be counterintuitive and having a
            syntax for a "short comparing" would be better for reading
            and understanding.

            Would make ternary comparison even shorter, too:

            ```
            let currentState = object.property.status === ('fail' :
            'ok') ? 'done' : 'doing'
            ```

            Please let me hear your thoughts on that :)

            Regards.







            _______________________________________________
            es-discuss mailing list
            [email protected] <mailto:[email protected]>
            https://mail.mozilla.org/listinfo/es-discuss
            <https://mail.mozilla.org/listinfo/es-discuss>





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

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

Reply via email to