2016-05-24 9 views
0

Javascriptで1行のコードを理解しようとしていますが、あまり明確ではありません。javascriptをより読みやすいコードで1行変換する

this._iconNeedsUpdate = !0,this._expandBounds(t), t instanceof L.MarkerCluster ? (e || (this._childClusters.push(t), t.__parent = this), this._childCount += t._childCount) : (e || this._markers.push(t), this._childCount++), this.__parent && this.__parent._addChild(t, !0) 

は、私は以下のコードを変換しようとしたが、それは動作しません:

this._iconNeedsUpdate = !0; 
this._expandBounds(t); 
if (t instanceof L.MarkerCluster) { 
    if (!e) { 
     this._childClusters.push(t); 
     t.__parent = this; 
    } else { 
     this._childCount += t._childCount; 
    } 
} else { 
    if (!e) { 
     this._markers.push(t); 
     this._childCount++; 
    } 
} 
if (this.__parent) { 
    this.__parent._addChild(t, !0); 
} 

任意のアイデア作品

ライン?

ありがとうございます!あなたの助けの後


、良いコードは次のとおりです。

this._iconNeedsUpdate = true; 
this._expandBounds(t); 

if (t instanceof L.MarkerCluster) { 
    if (!e) { 
    this._childClusters.push(t); 
    t.__parent = this; 
    } 
    this._childCount += t._childCount 
} else { 
    if (!e) { 
    this._markers.push(t); 
    } 
    this._childCount++; 
} 
if (this.__parent) { 
    this.__parent._addChild(t, true); 
} 

ありがとうございました!

+0

私は、拡張コードの最初の3行に6つの異なるJavaScriptの概念を数えました。正確には、あなたはそれについて理解していませんか? – Quentin

+0

この質問の[暗号化]タグは私を笑わせます。 –

+0

拡張バージョンは機能しますが、拡張バージョンは機能しませんか?それは問題ですか? (質問を明確にしてください) – SparK

答えて

0

3項条件演算子が最も低い優先度を持ちます。

また、(A || B), Cでは、Bが評価されるのは、Aが偽である場合に限りますが、Cは常に得られます。

だから、同等のコードは次のようになります。

this._iconNeedsUpdate = true; 
this._expandBounds(t); 

if (t instanceof L.MarkerCluster) { 
    if (!e) { 
    this._childClusters.push(t); 
    t.__parent = this; 
    } 
    this._childCount += t._childCount 
} else { 
    if (!e) { 
    this._markers.push(t); 
    } 
    this._childCount++; 
} 
if (this.__parent) { 
    this.__parent._addChild(t, true); 
} 
+0

最後の行を 'this .__ parent ...'に展開することもできますね – SparK

+0

私は可能でしたが、これは他のミニン化よりも一般的ですが読みやすいので読みにくいです。 – floribon

+0

普及しているにもかかわらず、新規ユーザーは、&&を使用して評価フローを制御するのが混乱していると考えられるため、このコードを試してみます。 – SparK

関連する問題