2
0
Эх сурвалжийг харах

[js] use Object.create for Type.createEmptyInstance

Dan Korostelev 8 жил өмнө
parent
commit
7cf09570b1

+ 1 - 1
std/js/Object.hx

@@ -27,7 +27,7 @@ import haxe.DynamicAccess;
 @:native("Object")
 extern class Object {
 	static function assign<T:{}>(target:T, sources:Rest<{}>):T;
-	@:pure static function create<T:{}>(proto:{}, ?propertiesObject:DynamicAccess<ObjectPropertyDescriptor>):T;
+	@:pure static function create<T>(proto:{}, ?propertiesObject:DynamicAccess<ObjectPropertyDescriptor>):T;
 	static function defineProperties<T:{}>(obj:T, props:DynamicAccess<ObjectPropertyDescriptor>):T;
 	static function defineProperty<T:{}>(obj:T, prop:String, descriptor:ObjectPropertyDescriptor):T;
 	static function freeze<T:{}>(obj:T):T;

+ 6 - 0
std/js/_std/Type.hx

@@ -114,10 +114,16 @@ 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 inline function createEmptyInstance<T>( cl : Class<T> ) : T {
+		return js.Object.create((cast cl).prototype);
+	}
+	#end
 
 	public static function createEnum<T>( e : Enum<T>, constr : String, ?params : Array<Dynamic> ) : T {
 		var f:Dynamic = Reflect.field(e,constr);