Browse Source

[js] make Type.createInstance somewhat typed

the js.Syntax.code should not really be needed and js.Syntax.construct should instead automatically insert parens when needed, but this "when needed" is something i couldn't figure out yet
Dan Korostelev 5 năm trước cách đây
mục cha
commit
5b859240f8
1 tập tin đã thay đổi với 4 bổ sung4 xóa
  1. 4 4
      std/js/_std/Type.hx

+ 4 - 4
std/js/_std/Type.hx

@@ -133,10 +133,10 @@ enum ValueType {
 			return js.Syntax.code("new empty()");
 			return js.Syntax.code("new empty()");
 		}
 		}
 	#else
 	#else
-	public static function createInstance<T>(cl:Class<T>, args:Array<Dynamic>):T
-		untyped {
-			return js.Syntax.code("new ({0})", Function.prototype.bind.apply(cl, [null].concat(args)));
-		}
+	public static function createInstance<T>(cl:Class<T>, args:Array<Dynamic>):T {
+		var ctor = ((cast js.lib.Function).prototype.bind : js.lib.Function).apply(cl, [null].concat(args));
+		return js.Syntax.code("new ({0})", ctor); // cannot use `js.Syntax.construct` because we need parens if `ctor` is fused in
+	}
 
 
 	public static inline function createEmptyInstance<T>(cl:Class<T>):T {
 	public static inline function createEmptyInstance<T>(cl:Class<T>):T {
 		return js.lib.Object.create((cast cl).prototype);
 		return js.lib.Object.create((cast cl).prototype);