HaxeDoc2

(やまだぃちぅ) #1

  • If a write access is made with a positive index which is out of bounds,null(or the default
    value (2.2) for basic types (2.1) on static targets (2.2)) is inserted at all positions between the
    last defined index and the newly written one.

  • If a write access is made with a negative index, the result is unspecified.


Arrays define an iterator (6.7) over their elements. This iteration is typically optimized by the
compiler to use awhileloop (5.14) with array index:
1 class Main {
2 static public function main() {
3 var scores = [110, 170, 35];
4 var sum = 0;
5 for (score in scores){
6 sum += score;
7 }
8 trace(sum); // 315
9 }
10 }


Haxe generates this optimized Javascript output:
1 Main.main = function() {
2 var scores = [110,170,35];
3 var sum = 0;
4 var _g = 0;
5 while(_g < scores.length){
6 var score = scores[_g];
7 ++_g;
8 sum += score;
9 }
10 console.log(sum);
11 };


Haxe does not allow arrays of mixed types unless the parameter type is forced toDynamic
(2.7):
1 class Main {
2 static public function main() {
3 // Compile Error: Arrays of mixedtypes are
4 // only allowed if the type isforced to
5 // Array
6 //var myArray = [10, "Bob", false];
7
8 // Array with mixedtypes
9 var myExplicitArray:Array=
10 [10, "Sally", true];
11 }
12 }


Trivia: Dynamic Arrays
In Haxe 2, mixed type array declarations were allowed. In Haxe 3, arrays can have mixed
types only if they are explicitly declared asArray<Dynamic>.
Free download pdf