Ver Fonte

[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 há 5 anos atrás
pai
commit
5b859240f8
1 ficheiros alterados com 4 adições e 4 exclusões
  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()");
 		}
 	#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 {
 		return js.lib.Object.create((cast cl).prototype);