fix some file extensions
This commit is contained in:
parent
68f8f3e56b
commit
f3a896c724
789 changed files with 91 additions and 62 deletions
35
Task/Classes/TIScript/classes.ti
Normal file
35
Task/Classes/TIScript/classes.ti
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class Car
|
||||
{
|
||||
//Constructor function.
|
||||
function this(brand, weight, price = 0) {
|
||||
this.brand = brand;
|
||||
this.weight = weight || 1000; // Resort to default value (with 'or' notation).
|
||||
this._price = price;
|
||||
}
|
||||
property price(v) // computable property, special kind of member function
|
||||
{
|
||||
get { return this._price; } // getter section
|
||||
set { this._price = v; } // setter section
|
||||
}
|
||||
function toString() { // member function, method of a Car.
|
||||
return String.printf("<%s>",this.brand);
|
||||
}
|
||||
}
|
||||
|
||||
class Truck : Car
|
||||
{
|
||||
function this(brand, size) {
|
||||
super(brand, 2000); // Call of constructor of super class (Car here)
|
||||
this.size = size; // Custom property for just this object.
|
||||
}
|
||||
}
|
||||
|
||||
var cars = [ // Some example car objects.
|
||||
new Car("Mazda"),
|
||||
new Truck("Volvo", 2, 30000)
|
||||
];
|
||||
for (var (i,car) in cars) // TIScript allows enumerate indexes and values
|
||||
{
|
||||
stdout.printf("#%d %s $%d %v %v, %v %v", i, car.brand, car.price, car.weight, car.size,
|
||||
car instanceof Car, car instanceof Truck);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue