Call method by variable

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

if (type === 'tables') {
	tablesInsert.call({ title: title });
}
else if (type === 'articles') {
	articlesInsert.call({ title: title });
}

I tried using

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

But this gives me window.method.call is not a function

Hello.

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.