hasOwnProperty vs methods - html5 target


I’ve noticed that hasOwnProperty() doesn’t work with methods (html5 target).


class My_class extends Sprite {  

      public var my_var:Int = 12;

      public function my_function():Void{


var my_instance:My_class  = new My_class();

my_instance.hasOwnProperty(my_var);    //  true

my_instance.hasOwnProperty(my_function);    // false [HTML5]  ,  true [Flash]

Do I miss something? Could you please advice.

Haxe classes do not have hasOwnProperty, but openfl.utils.Object does. Are you using that class? If so, perhaps we need an additional improvement in the class.

Look into https://api.haxe.org/Type.html and https://api.haxe.org/Reflect.html, specifically Reflect.hasField

I tested Haxe class as well as openfl.utils.Object. Unfortunately I received the same results with Reflect.hasField.

Some posts on the Haxe forum seem to confirm my thoughts - currently one cannot check if method exists [for HTML5 target] in other way than by error catching.

@klinek, as stated in the docs @singmajesty pointed to: Reflect.hasField() is only guaranteed to work on anonymous structs.
And Type.getInstanceFields() might be what you’re looking for (it comes with its own caveats).

See this https://try.haxe.org/#6e16c for example.