Closed
Description
Look at that code, especially the set method in DynamicArrayAccess
// need an array access on anonymous objects
abstract DynamicArrayAccess<T>(Dynamic<T>) from Dynamic<T>
{
public inline function new(d:Dynamic<T>) this = d;
@:arrayAccess
public function set(key:String, value:T):Void
{
// Reflect.setProperty was the first decision
// but I wanted to do it without Reflect
// and I suddenly remembered, that my abstract is perfect for that
new DynamicArrayAccess(this)[key] = value;
}
@:arrayAccess
public inline function get(key:String):T
{
return Reflect.getProperty(this, key);
}
}
class Test {
static function main() {
trace("Haxe is great!");
var a:Dynamic<Int> = {};
var a:DynamicArrayAccess<Int> = { k: 10 };
a["k"] = 20;
trace(a["k"]); // 20
}
}
The generated in js setter look like
_Test.DynamicArrayAccess_Impl_.set = function(this1,key,value) {
this1[key] = value;
};
How could that successfully compile? =)
Activity