I have a module where I process some raster images according to one of different functions/ statistical models. I am trying to find a way to allow the user to select which function to use. I have tried storing the functions as variables or properties but this doesn't work. So my question here is how can I call a function using its name (string format)? Any other workaround to dynamically choose which function to launch?
Here is the link to a simplified example.
Here is the code for the example:
//first possible function to use
var sumFun = function(a)
{
return ee.Number(a).add(3)
}
// second possible function to use
var subtFun = function(a)
{
return ee.Number(a).subtract(2)
}
//Storing functions as properties (DOESN'T WORK)
var modDic = ee.Dictionary({'sumFun':sumFun, 'subtFun': subtFun})
print(modDic)
var fun=modDic.get('sumFun')//calling function by its name
print(fun(4)) //doesn't work either atm
EDIT: corrected cast as dictionary