On 28/02/2007, at 11:06 PM, Klaus Hartl wrote: >> On 28/02/2007, at 8:17 AM, Joel Birch wrote: >>> Obviously the code has grown larger, mainly due to the switch >>> used to >>> parse the insertMethod option. Can you think of a better way of >>> doing >>> that whilst avoiding eval()? >>> >>> I have learnt a lot doing this so thanks for humouring me Klaus - I >>> know you are very busy at the moment. Oh, here's the new code: > > I spotted a little optimization: in the default branch > "menu.insertBefore(o.insertTarget);" is used. Thus you can remove the > case for "insertBefore", that one will just use the default... > > I like the switch statement a lot and think it is very readable, but > some people say switch smells (Hey Jörn ;-)) and that it is a sign > that > something could be refactored. Just so you know! I'm not sure about > that, the switch statement is considered very fast (google "duffs > device") and for predictable cases its fine for me. > > -- Klaus
I repeated that line in the default branch because, whilst it is the default setting, I wanted it first in the switch because I thought that would be the most used method and therefore the switch statement could exit earlier (faster) if it was found first. It's probably negligible though, so you are right, I'll change that. I thought the switch 'smelled' less that an eval would :) . Hey, this could be a good place for Jörn to prove his point and suggest how this could be refactored to avoid the switch :D Joel. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/