0
我想要避免評估循環中的條件,所以我想創建一個函數,返回變量中賦值的正確處理,然後使用該變量在循環動態地將一個函數分配給一個變量,然後在條件語句中使用它2.3.4
基本思路是這樣的:
export class myClass{
ref;
Treatment1(){code}
Treatment2(){code}
Treatment3(){code}
selectTreatment(){
if(condition1){
ref = Treatment1()
else if(condition2){
ref = Treatment2()
else (condition3){
ref = Treatment3()
}
executeTreatment(){
setInterval(ref(),300)
}
}
我不確定,但我認爲我對「這個」關鍵詞有問題!
我有資金這樣一個解決方案:
export class myClass{
ref:any;
Treatment1(){code}
Treatment2(){code}
Treatment3(){code}
selectTreatment():Function{
if(condition1){
return()=>{Treatment1()};
else if(condition2){
return()=>{Treatment1()};
else (condition3){
return()=>{Treatment1()};
}
executeTreatment(){
this.ref=this.selectTreatement();
setInterval(ref(),300);
}
}
不clear.You需要提供更多的'code'和細節。 – Sampath
我是新的打字稿,項目是私人的!只要有耐心,告訴我什麼不清楚,並認爲你回覆 –
如果你看到上面的'代碼'只有那麼你可以給別人解決方案嗎?你需要顯示所有相關的'代碼'。你在上面的代碼中使用'this'的地方? – Sampath