The fallback(handler)
method let’s the user define a method that is invoked whenever the initial method dispatch fails.
Here is an example of how to define a fallback.
Calling a setter method for a non-existent property defines it, thus the fallback is not applicable for setters.
let dynob = DynamicObject(): fallback(|this, method, args...| { return "Dispatch failed for method: " + method + ", with args: " + args: asList(): join(" ") }) println(dynob: casperGetter()) println(dynob: casperMethod("foo", "bar"))
Dispatch failed for method: casperGetter, with args: Dispatch failed for method: casperMethod, with args: foo bar