I have a string like this "namespace.fun1.fun2.fun3" passed from the client. It’s telling the server which function to use.
How do I safely run the function?
right now i’m doing:
var runthis = string.split('.')
namespace[runthis[1]][runthis[2]][runthis[3]]
How do I handle arbitrary depth of nesting safely?
A little function I wrote. I use it in most of my applications:
usage:
The first parameter is the object/method/property to resolve. The second (optional) parameter indicates whether or not the
lookup()method shall fail silently or throw an exception if some property or object could not get resolved. default is ‘throw’. To avoid that callIf
.fun3is a function, you can pass in any parameters into.execute()instead.if you just want to receive the property value, you can also call
.get()instead of.execute()