鍍金池/ 問(wèn)答/HTML/ return問(wèn)題

return問(wèn)題

問(wèn)題描述

發(fā)現(xiàn)一個(gè)很奇怪的問(wèn)題,關(guān)于輪詢請(qǐng)求無(wú)法被調(diào)用

問(wèn)題出現(xiàn)的環(huán)境背景及自己嘗試過(guò)哪些方法

我在輪詢調(diào)用一個(gè)方法時(shí),發(fā)現(xiàn)代碼無(wú)法跑到方法體內(nèi)(upInitialize為輪詢調(diào)用的方法),我在方法內(nèi)第一行console都無(wú)法輸出,當(dāng)我去掉respondsJudge時(shí)候方法的調(diào)用(if(res))后一切又正常了

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)
//調(diào)用輪詢方法

   componentDidMount() {
        this.initialize();
        loopReq('abcd',this.upInitialize);
    }
    //被調(diào)用的方法
     upInitialize =() =>{
        energyStorageInformation_img()
            .then(res => {
                if (respondsJudge(res)) {
                    this.setState({ energyStorageInformation_img: res.data.storageInfo })
                }
            });       
            }
     //respondsJudge方法
     export function respondsJudge(res){
  return res
}
//輪詢方法
export function loopReq(timerName,reqFn){
    window.myTimer = window.myTimer? window.myTimer:{};
    window.myTimer[timerName]=window.setInterval(()=>{
        reqFn();
    },Config.dataTimer);

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

希望能知道原因

回答
編輯回答
葬憶

給出的代碼沒(méi)有任何地方調(diào)用loopReq方法。

修改為:

 window.myTimer[timerName]=window.setInterval(reqFn, Config.dataTimer);
2017年3月12日 05:33