I think this is the best:
1) Variable in 'switch' is parameter for case
2) 'case' triggers if result of case expression is 'true'
So.
switch( aaa )
case <some expression>:
case <another expression>:
...
After JS processing
if( <modified some expression> ) {
if( <another modified expression> ) {
----- Original Message -----
From: "Dave Herman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: "Lars T Hansen" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Tuesday, October 16, 2007 6:19 PM
Subject: Re: 'switch' operator improvement
> But that's not what you proposed, is it? I understood your proposal to
> mean something more like:
>
> function f(g) {
> if (let (tmp = g()) // case g():
> (tmp is RegEx ? tmp.match(x) : x == tmp)) ....
> if ....
> }
>
> Dave
>
> [EMAIL PROTECTED] wrote:
>> I think switch ... case construction must be interpreted as:
>> function f(g) {
>> if( x == g() ) .... // case g():
>> if( .... // case ...
>> }
>>
>> ----- Original Message -----
>> From: "Dave Herman" <[EMAIL PROTECTED]>
>> To: "Lars T Hansen" <[EMAIL PROTECTED]>
>> Cc: <[EMAIL PROTECTED]>; <[email protected]>
>> Sent: Tuesday, October 16, 2007 6:04 PM
>> Subject: Re: 'switch' operator improvement
>>
>>
>>> It's clever, but it's a special case that may not abstract very
>>> smoothly. For example:
>>>
>>> function f(g) {
>>> switch (x) {
>>> case g():
>>> ...
>>> }
>>> }
>>>
>>> The behavior of my function depends on whether g() returns a RegEx or a
>>> non-RegEx. Maybe that's what you want, but it means it's an extra
>>> special case that you have to be aware of whenever abstracting a case
>>> statement.
>>>
>>> Dave
>>>
>>> Lars T Hansen wrote:
>>>> Neat, though it breaks backward compatibility -- each regexp is
>>>> converted to string before the comparison, IIRC. (Compatibility may
>>>> not be a big problem in practice in this case.)
>>>>
>>>> --lars
>>>>
>>>> On 10/16/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>>>> allow RegEx in case
>>>>>
>>>>> var str= 'a';
>>>>> switch( str ) {
>>>>> case /a/:
>>>>> alert('a');
>>>>> break;
>>>>>
>>>>> case /b/:
>>>>> alert('b');
>>>>> break;
>>>>> }
>>>>>
>>>>> _______________________________________________
>>>>> Es4-discuss mailing list
>>>>> [email protected]
>>>>> https://mail.mozilla.org/listinfo/es4-discuss
>>>>>
>>>>>
>>>> _______________________________________________
>>>> Es4-discuss mailing list
>>>> [email protected]
>>>> https://mail.mozilla.org/listinfo/es4-discuss
>> _______________________________________________
>> Es4-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es4-discuss
>
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss