我有下面的代碼:如何使用Typescript簡化此代碼?
let doNavigate = this.currentScreen === removedFqn;
if (doNavigate) { location.reload(); }
如何使用它我的打字原稿簡化?
我有下面的代碼:如何使用Typescript簡化此代碼?
let doNavigate = this.currentScreen === removedFqn;
if (doNavigate) { location.reload(); }
如何使用它我的打字原稿簡化?
(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(); }' –
OR:'let doNavigate = this.currentScreen === removedFqn? location.reload():null;' –