I Hate Clever Javascript Programmers [modified]
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
Yuck is this for work or for personal use?
Craigslist Troll: litaly@comcast.net "I have a theory that the truth is never told during the nine-to-five hours. " — Hunter S. Thompson
-
Yuck is this for work or for personal use?
Craigslist Troll: litaly@comcast.net "I have a theory that the truth is never told during the nine-to-five hours. " — Hunter S. Thompson
Personal use...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
Personal use...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
Bloody hell! this really needs a filter/translator to be understood or may take ages to be refined!! :omg: :omg: :omg: :omg: :omg: :omg: :omg: :omg: :omg: X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X|
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
If you work your head around inline IFs you'll find them really useful. I use them in C# all the time!!
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
If I read this correctly and my understanding of JavaScript precedence is correct, I think this is an ugly version of a big else-if statement. Something like this:
if (aw == null) {
return a0 === "!=";
} else if (a0 === "=") {
return a2 === aX;
} else if (a0 === "*=") {
return a2.indexOf(aX) >= 0;
} else if (a0 === "~=") {
return (" " + a2 + " ").indexOf(aX) >= 0;
} else if (!aX) {
return a2 && aW !== false;
} else if (a0 === "!=") {
return a2 !== aX;
} else if (a0 === "^=") {
return a2.indexOf(aX) === 0;
} else if (a0 === "$=") {
return a2.substr(a2.length - aX.length) === aX;
} else if (a0 === "|=") {
return a2 === aX || a2.substr(0, aX.length + 1) === aX + "-";
}return false;
which you could also write as
return (aW == null) ? a0 === "!="
: (a0 === "=") ? a2 === aX
: (a0 === "*=") ? a2.indexOf(aX) >= 0
: (a0 === "~=") ? (" " + a2 + " ").indexOf(aX) >= 0
: (!aX) ? a2 && aW !== false
: (a0 === "!=") ? a2 !== aX
: (a0 === "^=") ? a2.indexOf(aX) === 0
: (a0 === "$=") ? a2.substr(a2.length - aX.length) === aX
: (a0 === "|=") ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-"
: false;where this shows the IF on the left and the RETURN THIS on the left of the "?" on each line. Ugly. Un-maintainable. Yuck.
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
Finally I see what it is doing after 10 mins of staring at the code.
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
There is nothing clever here; the code was obfuscated with a tool; it was intended to be hard to understand; the original code is probably very readable.
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
Try rewriting it using if ... else ... instead of ? :, this might increase readability to the point where you'll understand it. But don't get your hopes high. This looks like some code intentionally obfuscated, potentially hand-crafted, intentionally written so it's not comprehensible, in order to prevent exactly what you are trying to do.
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
-
If I read this correctly and my understanding of JavaScript precedence is correct, I think this is an ugly version of a big else-if statement. Something like this:
if (aw == null) {
return a0 === "!=";
} else if (a0 === "=") {
return a2 === aX;
} else if (a0 === "*=") {
return a2.indexOf(aX) >= 0;
} else if (a0 === "~=") {
return (" " + a2 + " ").indexOf(aX) >= 0;
} else if (!aX) {
return a2 && aW !== false;
} else if (a0 === "!=") {
return a2 !== aX;
} else if (a0 === "^=") {
return a2.indexOf(aX) === 0;
} else if (a0 === "$=") {
return a2.substr(a2.length - aX.length) === aX;
} else if (a0 === "|=") {
return a2 === aX || a2.substr(0, aX.length + 1) === aX + "-";
}return false;
which you could also write as
return (aW == null) ? a0 === "!="
: (a0 === "=") ? a2 === aX
: (a0 === "*=") ? a2.indexOf(aX) >= 0
: (a0 === "~=") ? (" " + a2 + " ").indexOf(aX) >= 0
: (!aX) ? a2 && aW !== false
: (a0 === "!=") ? a2 !== aX
: (a0 === "^=") ? a2.indexOf(aX) === 0
: (a0 === "$=") ? a2.substr(a2.length - aX.length) === aX
: (a0 === "|=") ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-"
: false;where this shows the IF on the left and the RETURN THIS on the left of the "?" on each line. Ugly. Un-maintainable. Yuck.
I actually prefer the second version from a readability point of view (now that you've reformatted so it makes sense). Stick a comment at the top to say what it's doing and it wouldn't be so bad. The variable names and dynamic typing I'll admit is horrendous for readability though.
-
Personal use...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997Either way... I'm glad I'm not maintaining that guy's stuff. Personal or Professional, a good dev is not going to cut corners in the quality of their code in either. Or am I the only anal retentive coder out there.
I wasn't, now I am, then I won't be anymore.
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
The uncompressed source is on GitHub. https://github.com/mjijackson/shadowbox[^]
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
One line of code thing aside, this is a pretty idiomatic use of the ternary operator. What's so clever about it?
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
-
Like others have said ... that looks to me like Obfuscated code - emitted by a tool of some kind. If I had a developer working for me that wrote code like that I'd fire his ass. -Max
I agree. Although inline IFs are useful, that code looks as bad as it would look in the more traditional IF { } block form. I'm not convinced it's been generated by an obfuscator though.
-
There is nothing clever here; the code was obfuscated with a tool; it was intended to be hard to understand; the original code is probably very readable.
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
-
I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:
return (aW == null) ? a0 === "!=" : a0 === "="
? a2 === aX : a0 === "*="
? a2.indexOf(aX) >= 0 : a0 === "~="
? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
? a2 && aW !== false : a0 === "!="
? a2 !== aX : a0 === "^="
? a2.indexOf(aX) === 0 : a0 === "$="
? a2.substr(a2.length - aX.length) === aX : a0 === "|="
? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997modified on Thursday, April 28, 2011 3:50 PM
As others have said there is nothing demented or intentionally spiteful about this at all. They simply used an optimization tool (minifier), which removes all white space and uses the minimum amount of characters for variables. It compresses JavaScript quite a bit for downloading. It is a highly common, and very recommended, practice. The actual source code with all comments and descriptive variable names is on the project site.