Javascript call function by name


#1

I would like to call a function by its name. And possibly get list of all defined methods. For example:

fun loadDataAction(){...} fun saveDataAction(){...} ... val action = "saveData" ${{action + "Action"}}()

Is there a better way to do this than using when expression?

when (action){   "saveData" -> saveDataAction()   "loadData" -> loadDataAction()   ...   else -> wrongAction() }

It must work in javascript. So I can't use java reflection.


#2

I think the call function by name is not good way because it may be breaked, e.g. when you add or remove overloads. Additionally it'll break many IDE features like refactoring and navigation.

IMHO, when is good choise.

P.S. JS backend not support yet reflection, but it will do.