Typescript Loop with Delay
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to create a metronome with Typescript. I have this javascript code: ( function theLoop ( i ) { setTimeout ( function () { metronome . play (); if (-- i ) { theLoop ( i ); } }, 3000 ); // interval set to 3000 })( 10 ); // play it 10 times And I wanted to convert it into Typescript code. Unfortunately I don't know how to do this (espacially regarding the last line => })(10); Can someone help me with this? 回答1: As everyone said, typescipt is a superset of javascript so your code is valid typescript, but here's how to do it