C# içerisindeki "döngüler için" foreach
yapısını kullanmayı seviyorum. Bence çok temiz, verimli ve okunabilir.C# uygulamasına benzeyen TypeScript'te bir foreach yapısı var mı?
TipScript'te benzer bir yapı var mı? Yerine bu Örneğin:
setAuthorFilters(selectedAuthors)
{
selectedAuthors.forEach(x => this.setAuthorFilter(x));
this.updateUrl();
}
setAuthorFilter(selectedAuthor)
{
this.vm.SelectAuthors = this.vm.SelectAuthors.filter(x => x.id !== selectedAuthor.id);
this.vm.PreviousSelectedAuthors = this.vm.CurrentSelectedAuthors.slice();
this.vm.CurrentSelectedAuthors.push(selectedAuthor);
}
Bunu yapmak istiyorum:
setAuthorFilters(selectedAuthors)
{
foreach(var selectedAuthor in selectedAuthors)
{
this.vm.SelectAuthors = this.vm.SelectAuthors.filter(x => x.id !== selectedAuthor.id);
this.vm.PreviousSelectedAuthors = this.vm.CurrentSelectedAuthors.slice();
this.vm.CurrentSelectedAuthors.push(selectedAuthor);
}
this.updateUrl();
}
Not .. 'için ..' JS [Iterables] ile kullanılabilir (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol), ES6 öncesi çeviri, _not_ ile çalışır. – Kroltan
@Kroltan ayrıca, derleyicinin ES3 ortamlarında bile destek sağlayan bir “downlevelIteration” seçeneğine sahip olduğuna dikkat çekiyor. – Gerrit0