Prev | Current Page 872 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

When a
matching field exists in the instance it behaves normally.
class Resolver implements Dynamic
{
public static function main()
{
var r = new Resolver();
r.inexistant();
r.exist();
}
(continued)
Part III: Extending the Possibilities
476
public function new() { }
function __resolve(method : String) : Dynamic
{
return function()
{
trace(???Invoked the method: ??? + method);
}
}
public function exist()
{
trace(???I exist???);
}
}
To handle the method arguments, you can use the Reflect.makeVarArgs() method:
class Resolver implements Dynamic
{
public static function main()
{
var r = new Resolver();
r.inexistant(???Hello???, ???world???);
}
public function new() { }
function __resolve(method : String) : Dynamic
{
return Reflect.makeVarArgs(function(args) {
trace(???Invoked the method: ??? + method);
trace(???with arguments: ??? + args[0] + ??? ??? + args[1]);
});
}
}
The __setfield() magic method works similarly but it is executed when the value of an instance
variable is set and the variable is not defined in the class.


Pages:
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884