【发布时间】:2019-01-16 09:58:12
【问题描述】:
我是一个从 C# 开始的新游戏开发者。
现在我需要将我的一个游戏转移到 typescript。
我尝试在 typescript 中自定义一个列表,这是我在 C# 中非常熟悉的。 我的代码如下:
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 = [];
}
}
不过,我想制作一个数组,这样我就可以执行以下操作:
someList[i] = this.items[i];
我猜这类似于运算符重载,但我不太确定。
谁能告诉我怎么做?
提前致谢。
【问题讨论】:
标签: javascript typescript overloading operator-keyword