浏览代码

[js] quest complete (1/3)

closes #4232
Dan Korostelev 8 年之前
父节点
当前提交
87a970fdf3
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      std/js/_std/Type.hx

+ 5 - 1
std/js/_std/Type.hx

@@ -81,6 +81,7 @@ enum ValueType {
 		return e;
 	}
 
+	#if (js_es < 5)
 	public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T untyped {
 		switch( args.length ) {
 		case 0:
@@ -118,12 +119,15 @@ enum ValueType {
 		}
 	}
 
-	#if (js_es < 5)
 	public static function createEmptyInstance<T>( cl : Class<T> ) : T untyped {
 		__js__("function empty() {}; empty.prototype = cl.prototype");
 		return __js__("new empty()");
 	}
 	#else
+	public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T untyped {
+		return untyped __js__("new ({0})", Function.prototype.bind.apply(cl, [null].concat(args)));
+	}
+
 	public static inline function createEmptyInstance<T>( cl : Class<T> ) : T {
 		return js.Object.create((cast cl).prototype);
 	}