I have a lot of code taking many keys from a dynamic var qry.name qry.address etc, I want to change the dynamic to some type that would use the string to calculate the value, like es6 proxy, one way is with abstract arrayAccess but this will require me to change all calls to qry[“name”], can this be done in haxe?
var name=qry.name;
//should become
var name=qry.get("name");
It just so happens I have this bit of code obtained from @back2dos :
typedef SomeData = {
final attributes:Attributes;
}
abstract Attributes(Dynamic<String>) from Dynamic<String> {
@:op(a.b) public inline function get(name:String):String return untyped this[name];
public function keyValueIterator()
return (this:haxe.DynamicAccess<String>).keyValueIterator();
}
So the attributes would have a get method which operates as you describe, e.g.: data.attributes.get(name); (without the quotation marks). Remember the “name” in the get method is simply any key you are trying to retrieve.