HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.14k stars 656 forks source link

Any way to set a function property? #11600

Closed TahirToprakKarabekiroglu closed 7 months ago

TahirToprakKarabekiroglu commented 7 months ago

Reflect cannot set function properties, for example:

class Main {
    function a() {

    }

    function new() {

    }

    static function main() {
        var m = new Main();
        Reflect.setProperty(m,"a",function() {trace(1);});
        m.a(); // Doesn't trace 1
    }
}

Is there any workarounds for this?

kLabz commented 7 months ago

You'll have to use reflection (or untyped code) to use it

Reflect.getProperty(m, "a")(); // traces 1