Friday 15 May 2015

javascript - How is this minified JS the same as this uncompressed version? -


Then it looks like my uncompressed:

  function extract dropdown value () { Var all_selected = true; $ ('.Variant_options select'). Each (function () {if (this.selectedIndex == 0) {all_selected = false;}});   

This compressed version is:

  extractDropdownValues ​​() {var e =! 0; Select $ (".Variant_options"). Each (function) {this.selectedIndex == 0 & amp; & Amp; (D = 1)!});   

I E =! 0 is confused with the compressed version of all_selected = true and it.Blied Index == 0 if the statement is in the compressed version, this If is indicating this index == 0, then set it to false.

But in the compressed version, it seems that this is the value of selected index for 0 and & amp; Amp; Amp; Amp; Amp; Amp; all_selected = false (i.e. e =! 1 ) for . But I do not want the result as if condition, which should be the result after if condition is satisfied.

Am I reading this wrong?

PS compressed version is not working in production, but is working in uncompressed dev. I am not sure that both are correlated, but on the surface, they do not consider me equal.

Edit 1

As I suspect, I read the JS Run mini-js through prefifiers, and the result is:

  function extractdowndown value () {var e =! 0; $ (".variant_options select"). Each (function () {this.selectedIndex == 0 & amp; (e =! 1)});   

Soo ... Ah ... WTF is getting here?

0 is false in Boolean form, so the boolean prohibition of 0 (false) is true.

Similarly, 1 boolean form is correct, so the boolean reject of 1 is wrong.

& amp; Amp; Amp; & Amp; Amp; Amp;; is short circuiting and operator, which means that as soon as it knows that its results get a quick return - if its first operand is wrong, then it returns false if its first operation is correct, after that He evaluates the second operand and gives returns.

Then E =! 1 Only if this.selectedIndex == 0 is true (because if it is wrong, then it knows that it is returning incorrectly and is closing soon).

No comments:

Post a Comment