default args and inline vars should be constent, as a result structs cannot be used, even if all of their children are const, which is understood as they have inner mutibility.
However this makes problems when converting code from javascript where everything not computed (any JSON literal) would be allowed.
untyped didn’t help here, any way to circumvent this restriction?
One way would be use a string constent and find replace in the generated code, not pretty…
class Test {
static function main() {
trace("Haxe is great!");
f({a:1});
}
static function f(_arg:Dynamic={}){
trace(_arg);
}
}
Sorry for not being clear, I have a problem and I am trying to express it, I appriciate your help, I am sorry if my words doesn’t express my problem, maybe I am too tired.
Combining null coalsing with sellf assignment is a very good and clean idea.
Initially I was trying to use if(_args==null) _arg={} but was too verbose, also I do not like to modify arguments (for fear of reference arguments, history of other languages c++, visual basic, in haxe this wouldn’t be a problem as long you overwrite the var, not modifying the class).
I have found a funny thing : Try Haxe!
This Haxe code :
class Test {
static function main() {
trace("Haxe is great!");
f();
f({a: 1});
}
static function f(?_arg:Dynamic){js.Syntax.code("}
static f(_arg={}){");
trace( _arg );
}
}
Turns into this JS code which works fine (take a look at the second f signature with the default { } argument :