浏览代码

[js] fixed Array#slice when end is null

Andy Li 10 年之前
父节点
当前提交
7dd8dbe72d
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      std/js/_std/Array.hx

+ 7 - 2
std/js/_std/Array.hx

@@ -31,7 +31,6 @@ extern class Array<T> {
 	function push(x : T) : Int;
 	function reverse() : Void;
 	function shift() : Null<T>;
-	function slice( pos : Int, ?end : Int ) : Array<T>;
 	function sort( f : T -> T -> Int ) : Void;
 	function splice( pos : Int, len : Int ) : Array<T>;
 	function toString() : String;
@@ -48,7 +47,7 @@ extern class Array<T> {
 #if js_es5
 	function indexOf( x : T, ?fromIndex:Int ) : Int;
 	function lastIndexOf( x : T, ?fromIndex:Int ) : Int;
-
+	function slice( pos : Int, ?end : Int ) : Array<T>;
 #else
 	inline function indexOf( x : T, ?fromIndex:Int ) : Int {
 		return @:privateAccess HxOverrides.indexOf(this,x,(fromIndex!=null)?fromIndex:0);
@@ -57,6 +56,12 @@ extern class Array<T> {
 	inline function lastIndexOf( x : T, ?fromIndex:Int ) : Int {
 		return @:privateAccess HxOverrides.lastIndexOf(this,x,(fromIndex!=null)?fromIndex:length-1);
 	}
+
+	// for IE8
+	// see https://github.com/HaxeFoundation/haxe/issues/4460#issuecomment-128156336
+	inline function slice( pos : Int, ?end : Int ) : Array<T> {
+		return (untyped this).slice(pos,(end!=null)?end:length);
+	}
 #end
 
 	inline function copy() : Array<T> {