Is it just me or does the closure version read more clearly?
As to eval itself, it's obviously not 'evil'. But nontrivial use can make code unreadable:
doSomeStuff()
eval(someVar)
doOtherStuff()
this can be read as doSomeStuff()
doPrettyMuchAnythingConceivable()
doOtherStuff()
This neatly removes any ability to effectively reason about the code.Seems like decreasing the font size a few points would have clearer a better solution than clouding the could with loops and `eval()`/closures..
Depending on the context, perhaps showing the first class "full size", and abbreviating the other two would work.. or, show the code for one, then explain "we define another class named C, which prints C, and final one named D, which prints D" - it is a "talk", after all..
That's why I consider `eval` to be "evil" - there's almost always a better way..