Strange behavior of uglifyed javascript code with string comparison
<p>I created a jsfiddle here for a strange case : <a href="http://jsfiddle.net/YGcDR/" rel="nofollow">http://jsfiddle.net/YGcDR/</a> </p>

<p>The idea is that an equality comparison function (probably not optimized) is causing a bug in the select2 library, when optimized with uglifyjs. (The bug is pretty hard to diagnose, all we know is that the patch associated to <a href="https://github.com/ivaynberg/select2/issues/840" rel="nofollow">https://github.com/ivaynberg/select2/issues/840</a> fixes it, and the only thing the patche changes is the comparison code. So I'm really trying to form an hypothesis here !)</p>

<p>A patched version of the same function seems to behave properly, both in optimized and unoptimized case. </p>

<p>The 'meat' of the code is comparision done like this : </p>

<pre><code>if (a.constructor === String) return a === b + "";
if (b.constructor === String) return b === a + "";
</code></pre>

<p>vs</p>

<pre><code>if (a.constructor === String) return a + "" === b + "";
if (b.constructor === String) return b + "" === a + "";
</code></pre>

<p>The generated code is slightly different in both case : </p>

<pre><code>n.constructor===String?n===t+"":t.constructor===String?t===n+"":!1
</code></pre>

<p>vs</p>

<pre><code>n.constructor===String?n+""==t+"":t.constructor===String?t+""==n+"":!1}
</code></pre>

<p>The problem is, I can not think of any set of entries for a and b that could cause the difference. At first I though it could be a difference between <code>var a = "Foo" and var b = new String("Foo")</code>, but this does not seem to be the case. Anyone seeing why this could fail ? </p>

<p>Thanks</p>
