Call method by variable


I’m using validated methods. How can I use a variable for a method name?

if (type === 'tables') {{ title: title });
else if (type === 'articles') {{ title: title });

I tried using

window[type + 'Insert'].call({});

But this gives me is not a function



If you encounter this problem on the server side, you can try gobal[type+‘Insert’].call({});
I think it is the equivalent of window.

If that does not work either you can try eval(type+‘Insert’).call({}); (However eval is ,as far as I investigate, a little dangerous)

I’m not sure whether it is the best solution but it worked for me.


Use ‘this’ instead of window. On client, ‘this’ is window. On server ‘this’ is global.