How can I call the following?
var ccall="search.clearMultiSelect";
I have tried the following:
window[ccall]();ccall();Both didn't work (and I get why). I was able to achieve it by eval but is there any other way without using eval?
I cannot split the string or manipulate the string, except for adding something at the beginning or end.
Basically the server, in it's response, contains the name of the function to execute on success of an operation, which in this case is as above.
window[ccall]() wouldn't work because window doesn't contain a function by the name "search.clearMultiSelect". If you can use split, try something like:
window[ccall.split('.')[0]][ccall.split('.')[1]]();
For a function of depth greater than 2, you can loop through the split('.') array:
var f = window;
var ccallArray = ccall.split('.');
for (var i = 0; i < ccallArray.length; i++){
f = f[ccallArray[i]];
}
f();
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With