Javascript 如何使用Typescript简化此代码?
我有下一个代码:Javascript 如何使用Typescript简化此代码?,javascript,angular,typescript,Javascript,Angular,Typescript,我有下一个代码: let doNavigate = this.currentScreen === removedFqn; if (doNavigate) { location.reload(); } 如何使用Typescript简化它?尽管三元运算符更简单,但它不可读。你可以看到,当它没有像我在这里做的那样正确地缩进时,它看起来是多么丑陋 (this.currentScreen === removedFqn) ? location.reload() : ''; this.currentS
let doNavigate = this.currentScreen === removedFqn;
if (doNavigate) { location.reload(); }
如何使用Typescript简化它?尽管三元运算符更简单,但它不可读。你可以看到,当它没有像我在这里做的那样正确地缩进时,它看起来是多么丑陋
(this.currentScreen === removedFqn) ? location.reload() : '';
this.currentScreen === removedFqn?location.reload():null;
最好使用if,因为性能差异几乎可以忽略不计
if(this.currentScreen === removedFqn){
location.reload();
}
你可以这么做
if (this.currentScreen === removedFqn) { location.reload(); }
但是如果this.currentScreen==removedFqn{location.reload;}或者:让doNavigate=this.currentScreen==removedFqn,那么这与TypeScript无关?location.reload:空;