I do not want to use Switch in my code, so I\'m looking for some alternative
Example with Switch:
function write(what) {
switch(w
Question 2:
Generally, if you can replace custom control structures with a dictionary lookup, you're perfectly fine. It's easy to read and highly elegant -- stick with it.
As I said, it's great. The only thing I can add to your solution is that it's perhaps better to localize your colors
.
function write(what) {
var colors = [];
colors['Blue'] = function() { alert('Blue'); };
colors['Red'] = function() { alert('Red'); };
colors[what]();
}