2016-11-22 1 views
0

さて、私の機能の完全なソースを聞いてください。私は、 "////////////"で囲まれた部分が繰り返されることを願っています。新しい機能も機能します。強調表示された関数を新しい関数にプルしようとすると、非常に混乱し、多くのエラーが発生しました。このJS関数の一部を30秒ごとに何度も繰り返す方法はありますか?

function reWebLogOn(steam, callback) { 
    steam.webLogOn(function(newCookie){ 
     helper.msg('webLogOn ok'); 
     cookies = newCookie; 
     offers.setup({ 
      sessionID: currentSessionId, 
      webCookie: newCookie 
     }, function(){ 
      if (typeof callback == "function") { 
       callback(); 
      } 
     }); 
     var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
    { 
     steamid:   config.steamid, 
     identity_secret: config.identitySecret, 
     device_id:  device_id, 
     webCookie:  newCookie, 
    }); 


/////////////////////////////////////////////////////////////////////////////////////////////////////////// 


    steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations) 
{ 
    if (err) 
    { 
     console.log(err); 
     return; 
    } 
    console.log('steamcommunityMobileConfirmations.FetchConfirmations received ' + confirmations.length + ' confirmations'); 
    if (! confirmations.length) 
    { 
     return; 
    } 
    steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result) 
    { 
     if (err) 
     { 
      console.log(err); 
      return; 
     } 
     console.log('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result); 
    }).bind(this)); 
}).bind(this)); 

/////////////////////////////////////////////////////////////////////////////////////////////////////////// 

    }); 
} 
+0

は 'FetchConfirmations'です。ループしたい内容、または内容を内容にしていますか? – Jacksonkr

答えて

0

利用タイマの間隔は

setInterval(function() { 
    //.. part that should be repleated 
}, 30*1000); 
+0

追加してくれてありがとう、ありがとう! – Petras

+0

@Petras U r welcome :) –

0

window.setInterval()便利だろうあなたの友達です。 与えられた時間間隔で機能を実行します。 たとえば、setInterval(()=>console.log("foo"),100)は100msごとにコンソールに「foo」と記録します。

function reWebLogOn(steam, callback) { 
    steam.webLogOn(function(newCookie){ 
     helper.msg('webLogOn ok'); 
     cookies = newCookie; 
     offers.setup({ 
      sessionID: currentSessionId, 
      webCookie: newCookie 
     }, function(){ 
      if (typeof callback == "function") { 
       callback(); 
      } 
     }); 
     var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
    { 
     steamid:   config.steamid, 
     identity_secret: config.identitySecret, 
     device_id:  device_id, 
     webCookie:  newCookie, 
    }); 


/////////////////////////////////////////////////////////////////////////////////////////////////////////// 

setInterval((function(){ 
    steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations){ 
    if (err) 
    { 
     console.log(err); 
     return; 
    } 
    console.log('steamcommunityMobileConfirmations.FetchConfirmations received ' + confirmations.length + ' confirmations'); 
    if (! confirmations.length) 
    { 
     return; 
    } 
    steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result) 
    { 
     if (err) 
     { 
      console.log(err); 
      return; 
     } 
     console.log('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result); 
    }).bind(this)); 
    }).bind(this)); 
}).bind(this),30000) 
0

あなたのコードをsetInterval(function(){}、1000)タイマーの中に入れたり、再帰呼び出しをしたりしてください。

関連する問題