How would you call a function from a string, possibly including a scope, and without using eval.
The idea is that I want to specify a callback inside an a dragEndCallback attribute, and call it giving the drag start and end objects as parameters. Some kind of generic drag and drop in my case.
Most people will tell you to use eval, but it’s unsafe, slow, and a really bad idea overall.
Here are some sample strings that I would like to support:
"NamespaceA.functionName"
"functionName"
"NamespaceB.NamespaceA.functionName"
"ClassB.methodName"
Here is a generic, clean, and convenient way to do it. It returns undefined if the function was not found.