How can I execute a Javascript function such this:
cursor.continue(parameters)
By using a string to identify the function name, without using eval? Something like this:
cursor.callMethod("continue", parameters);
Is this possible?
How can I execute a Javascript function such this:
cursor.continue(parameters)
By using a string to identify the function name, without using eval? Something like this:
cursor.callMethod("continue", parameters);
Is this possible?
If you are in control of callMethod, and the function belongs to an object or is global, then yes, that's possible.
For example, if the target function is a method of the same object where callMethod is:
var cursor = {
callMethod: function(method, params) {
this[method].apply(this, params);
},
continue: function() {}
}
cursor.callMethod("continue", [1, 2, 3]);
cursor is an IndexedDB cursor, so techfoobar's solution is more appropriate, but definitely +1 for the literal implementation of my example method.