Can I somehow avoid the need to define a local function for each function that I need to pass into a class?
E.g. check out following:
function createDataProviderNone() as IDataProvider { return new DataNone(); }
function createDataProviderBattery() as IDataProvider { return new DataBattery(false); }
function createDataProviderBatteryInDays() as IDataProvider { return new DataBattery(true); }
static const NONE = new DataType(0, "--", new Lang.Method(:createDataProviderNone));
static const BATTERY = new DataType(1, "Battery (%)", new Lang.Method(:createDataProviderBattery));
static const BATTERY_IN_DAYS = new DataType(2, "Battery (Days)", new Lang.Method(:createDataProviderBatteryInDays));
I want to define my data type instances once and I want them to have a function that will return the underlying data provider instance - I can do this like I do it above, but I would prefer some inlined style like following:
static const NONE = new DataType(0, "--", new Lang.Method({ return new DataNone(); }));
static const BATTERY = new DataType(1, "Battery (%)", new Lang.Method({ return new DataBattery(false); });
static const BATTERY_IN_DAYS = new DataType(2, "Battery (Days)", new Lang.Method({ return new DataBattery(true); });
But that is not working. Is there a syntax to achieve what I want? I want the equivalent to following in C++:
static const NONE = new DataType(0, "--", new std::function([](){ return new DataNone(); });