'switch' operator improvement

Dave Herman dherman at ccs.neu.edu
Tue Oct 16 08:04:01 PDT 2007


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, Eugen.Konkov at aldec.com <Eugen.Konkov at aldec.com> wrote:
>>
>> allow RegEx in case
>>
>> var str= 'a';
>> switch( str ) {
>>   case /a/:
>>     alert('a');
>>     break;
>>
>>   case /b/:
>>     alert('b');
>>     break;
>>   }
>>
>> _______________________________________________
>> Es4-discuss mailing list
>> Es4-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es4-discuss
>>
>>
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss




More information about the Es4-discuss mailing list