Well done Mr Már, from "treason" now we are back to reason. Almost ;o) Dare I say, the last nail in the coffin of the jQuert.fn.cond, might be this :
jQuery('a').each(function(){ switch(x) { case 1 : $(this).css({ color: 'blue' }): break ; case 2 : $(this).css({ color: 'red' }): break ; default : $(this).css({ color: 'green' }); } }); Unfortunately, for some, this is "too many keystrokes" ... And peculiarly (then very young and rushed) Mr B. Eich forgot to make result of the switch available, so this is not possible in javascript : $(this).css({ color: switch(x) { case 1 : 'blue' ; break ; case 2 : 'red' ; break ; default : 'green' ; } }) ; Unless done like this : eval( 'switch(x){ case 1: "blue"; break; case 2: "red"; break; default: "green" } ' ) ; Which is somewhat clumsy. So some have concluded they "must help" everyone with function simillar to this : cond( x, 1, "blue", 2, "red", default, "green" ) ; // or call it 'my_switch' Now the 'excitement' is high, because one can write this : $(this).css({ color: switch(x) { cond( x, 1, "blue", 2, "red", default, "green" ) } }) ; For some this is "Awesome", while for some this is "obfuscation" . I vote for ECMA5 to simply allow assignment with the 'switch' statement : //My ECMA5 proposal var color = switch(x) { case 1: "blue"; break case 2: "red"; break default: "green" } ; --DBJ On Jun 11, 9:03 am, "stephb...@googlemail.com" <stephb...@googlemail.com> wrote: > > ...how is this `.cond()` thing supposed to be more readable/useful/ > > jQuery-ish > > I admit, I'm not convinced I'll ever use it! > > > pray tell? > > It doesn't do the same thing. Where .each runs the tests for every > element in the collection and returns the collection, .cond() runs the > tests once and returns anything you like. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---