|
Spec-Zone .ru
спецификации, руководства, описания, API
|
Here are some definitions and uses of variables of required types: Integer, Number, Boolean, and String
var x : Number; // x initially 0.0 var m : Integer; // m initially 0 var isBig : Boolean; // isBig initially false var word : String; // word initially "" m = 42; x = 0.25 * m + 2.1e4; isBig = x > 1000; word = if (isBig) "Big" else "Small";
Here is a definition and use of a variable of optional type:
class Foo {
var zing : Integer;
}
var fu : foo; // fu initially null
fu = Foo {zing: 17}
And a definition and use of a sequence type:
var names : String[]; // names initially [] names = ['Olof', 'Ellen', 'Steve', 'Claire']; insert 'Bonnie' into names; // add 'Bonnie' to the end of names sequence names[1] = 'Donna'; // set the element at 1 (previously 'Ellen') to 'Donna'
Note that sequences are immutable, so technically, each line above assigns a new sequence to names.