I'm a new game developer who started from C#.
Now I need to transfer one of my games to typescript.
I tried to customize a list in typescript which i'm very familiar to in C#. my code is like below:
export class List {
private items: Array;
constructor() {
this.items = [];
}
get count(): number {
return this.items.length;
}
add(value: T): void {
this.items.push(value);
}
get(index: number): T {
return this.items[index];
}
contains(item: T): boolean{
if(this.items.indexOf(item) != -1){
return true;
}else{
return false;
}
}
clear(){
this.items = [];
}
}
Still, I want to make like a array so I can do things like:
someList[i] = this.items[i];
I guess it's something like operator overload but I'm not quite sure.
Can any one tell me how to make it?
Thanks in advance.