Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions std/js/_std/Type.hx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ enum ValueType {
}

public static inline function createEmptyInstance<T>(cl:Class<T>):T {
if (String == cast cl)
return cast "";
return js.lib.Object.create((cast cl).prototype);
}

Expand Down
9 changes: 5 additions & 4 deletions std/lua/_std/Type.hx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ enum ValueType {
return __new__(cl, lua.TableTools.unpack(cast args, 0));
}

public static function createEmptyInstance<T>(cl:Class<T>):T
untyped {
return _hx_new(cl.prototype);
}
public static function createEmptyInstance<T>(cl:Class<T>):T {
if (String == cast cl)
return cast "";
return untyped _hx_new(cl.prototype);
}

public static function createEnum<T>(e:Enum<T>, constr:String, ?params:Array<Dynamic>):T {
var f:Dynamic = Reflect.field(e, constr);
Expand Down
2 changes: 2 additions & 0 deletions std/neko/_std/Type.hx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ enum ValueType {
}

public static function createEmptyInstance<T>( cl : Class<T> ) : T untyped {
if (String == cast cl)
return cast "";
var o = __dollar__new(null);
__dollar__objsetproto(o,cl.prototype);
return o;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/unit/teststd/TestType.hx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TestType extends unit.Test {
//eq(t.b, "bar");

// createEmptyInstance
//eq(Type.createEmptyInstance(String),"foo");
eq(Type.createEmptyInstance(String),"");
//eq(Type.createEmptyInstance(null, []), null);
var c = Type.createEmptyInstance(ClassWithCtorDefaultValues);
eq(c.a, null);
Expand Down
Loading