The following code is working fine:
function a() { console.log("a"); };
function b() { console.log("b"); };
var F = {1:a,2:b};
F[1](); // log "a"
F[2](); // log "b"
but this one does not:
function a() { console.log("a"); };
function b() { console.log("b"); };
var A = 1;
var B = 2;
var F = {A:a,B:b};
F[A](); // log "TypeError : F[A] is not a function"
The idea is that A and B would be constant integer, used just for the sake of code readability. I know there are no "const" in javascript, but you get the idea.
What would be the clean way to get something like this work ? (I do not care that much if A and B are effectively constant or not at the end, just having them upper case indicates my future me not to change their value).