やりたい事
現在以下のようになっています。
見づらいので綺麗にしたいです。
js
1localStorage_x = localStorage.getItem('x') 2x_default = false 3this.x = (localStorage_x == null) ? x_default : (localStorage_x === 'true')
文字列を Boolean にキャストすると全て true
になるようです。
Boolean('false')
を false
と評価してくれれば上記のコードが以下のようにスッキリします。
javascript
1this.x = Boolean(localStorage.getItem('x'))
何かいい案はありますでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/27 13:15 編集