lundi 29 décembre 2014

haxe case pattern reuseing - maybe as a variable

Is there any way to save patterns in haxe? I have several switch functions, and some of them have the same pattern, and to make the code cleaner, I'd like to save them to a common array or something. So I have something like



switch (field) {
case 'x' | 'y' | 'color' : doThis();
}
//...other function...
switch (field) {
case 'x' | 'y' | 'color' : doThat();
}


and I want to have something like



myPattern = 'x' | 'y' | 'color';

switch (field) {
case myPattern : doThis();
}
//...other function...
switch (field) {
case myPattern : doThat();
}

Aucun commentaire:

Enregistrer un commentaire