jashkenas/coffee-script — Issue #2112: switch proposal
Author: johngeorgewright
Created: 2012-02-09 16:45:51+00:00
State: open

Hello there,

I've just started using coffee script with node.js and I'm quickly falling in love. I have a proposal though... I understand the logic behind the switch statements generally requiring to break after each case, however, in most other languages I quite often like to use the fall through option. I.e:

switch (resp.statusCode) {
case 409:
console.log('Product is already assigned.');

case 404:
save(item);
break;

case 500:
console.error('Something went really wrong');
break;
}

When writing this in coffee script I have to duplicate code:

switch res.statusCode
when 409
console.log 'Product is already assigned.'
save item
when 404 then save item
when 500 then console.error 'Something went really wrong.'

What would be great is if I could somehow recreate the usual fall through... with something like a "continue" command:

switch res.statusCode
when 409
console.log 'Product is already assigned.'
continue
when 404 then save item
when 500 then console.error 'Something went really wrong.'

I know this example is very small, but sometimes there is a fair amount that can be abstracted with the fall through.

Thanks,
John