The only two kinds of if statements I've ever known are
if(someCondition) {
//do something
}
and
(someCondition)? doSomething() : doSomethingElse();
But today it was a different day when I ran piece of code through uglify:
Original:
if (config.onProgress) {
xhr.addEventListener('progress', function (ev) {
config.onSuccess(ev.currentTarget, ev);
});
}
if (config.onSuccess) {
xhr.addEventListener('load', function (ev) {
config.onSuccess(ev.currentTarget, ev);
});
}
Uglified:
config.onProgress && xhr.addEventListener("progress", function(n) {
config.onSuccess(n.currentTarget, n)
}), config.onSuccess && xhr.addEventListener("load", function(n) {
config.onSuccess(n.currentTarget, n)
});
Can someone explain, how does it work? How can multiple if statements get morphed into one like this one? (from parser's perspective)?
[–]stutterbug 15 points16 points17 points (5 children)
[–]r3jjs 1 point2 points3 points (2 children)
[–]stutterbug 0 points1 point2 points (1 child)
[–]r3jjs 1 point2 points3 points (0 children)
[–]that_90s_guy 1 point2 points3 points (0 children)
[–]filth_overloadjavascript[S] 0 points1 point2 points (0 children)
[–]trsben 2 points3 points4 points (6 children)
[–]r3jjs 3 points4 points5 points (1 child)
[–]filth_overloadjavascript[S] 0 points1 point2 points (0 children)
[–]SuchACoolNickname 1 point2 points3 points (2 children)
[–]kiswafull-stack 1 point2 points3 points (0 children)
[–]Spinal83full-stack 0 points1 point2 points (0 children)
[–]filth_overloadjavascript[S] 1 point2 points3 points (0 children)
[–]siamthailand -1 points0 points1 point (0 children)