Variables - xkp/Doc GitHub Wiki
XS is a hybrid typed language, this means it sports a type system while allowing untyped variables. the keyword var is used in the language as a type. In fact, "var" in xs does not stand for "variable" but for "variant";
method foo(int x, var y, z)
{
var copy = x;
x = z; //dynamic cast
int yy = y;
if (x > yy && x > y)
{
x = copy; //static cast
}
return z as float; //explicit cast
}
This typing schema applies as well to objects:
method foo(bar)
{
int x = bar.x(); //late binding
alert(bar.y);
}
Arrays:
Frankly, containers are not completely finished. At the moment there is support for an array type, this type admits its type in template fashion:
property foo : array<string>;
property bar : array; //array of vars
method foobar(array<int> a)
{
array result = []; //can be initialized
for(var i in a) //type gets deducted (is is int)
{
result += i + 20; //+= adds items
}
return result;
}