私はputTestQuestionResponses()関数が以前のバージョンがすでに実行されていたIFを実行するのを止める方法を尋ねて、スタックオーバーフローに関する質問を提出しました。Typescriptのvarとletの違いは何ですか?
返信は、このコードの2行目の処理フラグに追加することでした。
「var」の代わりに「let」を使用する理由を教えてください。
var promisePutTestQuestion;
let processing = false;
onEnter: ['$interval', 'questionService',
($interval, qus: IQuestionService) => {
promisePutTestQuestion = $interval(() => {
if (processing)
return;
processing = true;
qus.putTestQuestionResponses()
.then(() => processing = false)
}, 5 * 1000);
}],
onExit: ['$interval', ($interval) => {
$interval.cancel(promisePutTestQuestion);
}]
私は読むことをお勧めしますhttps://basarat.gitbooks.io/typescript/content/docs/let.html –
これは、httpと重複してもそうです:// stackoverflowの.com/questions/32051173/var-and-let-in-typescipt-1-5 – ciekawy
http://stackoverflow.com/questions/762011/let-keyword-vs-var-keyword –