Re:Using Dispatch Tables to Avoid Conditionals in JavaScript
by taf2 on Monday May 13, 2013 @10:09AM
(#5698712)
yeah, i kinda agree.. in this case I'd have done something more like:
Perhaps I'm just comment trolling though - totally depends on how the code would have been used...
[ Parent
| on HN ]
Re:Using Dispatch Tables to Avoid Conditionals in JavaScript
by chime on Monday May 13, 2013 @12:15PM
(#5699525)
Actually my code ends up looking pretty much like yours. I use CoffeeScript and was writing a simplified JS equivalent off the top of my head since this post was about JS. Similar to your Renderer, I have a DrawForm class that iterates through DrawField class objects which provide the checkbox(), radio() etc. methods.
My point was that in the end, you get to do dynamic function instantiation, which is pretty awesome in JS.