0
有兩種類別: 當使用類作爲一個類型,不能使用它的靜態方法
class Observer {
static Update(value) { }
}
class ObserverList {
private observerList: Observer[];
constructor() {
this.observerList = [];
}
Get(index: number): Observer {
if (index > -1 && index < this.observerList.length) {
return this.observerList[index];
}
}
}
我用的則是這樣的:
var obList=new ObserverList();
obList.Get(3).Update();
然後我留神Property 'Update' does not exist on Type Observer
。 這是使用Class Observer作爲返回類型的錯誤方法嗎?
這是哪一種語言?您可能需要添加標籤,以便更多人看到此問題。 – anatolyg
@anatolyg,它是打字稿。 – qxg
如果某個方法是「靜態」,這意味着它的工作方式與該類的特定對象沒有任何關聯。如果你的方法確實需要是'static',那麼你必須直接在類Observer.Update()上調用它,而不是在單個觀察者實例上調用它。 – DCoder