I recently ran across the following [effective] syntactical construct:
d <= f && func3();
The actual construct is of the form:
d > f ? a > b ? func1() : func2() : d <= f && func3();
What is the purpose of this construct?
My best guess is that func3 will only be executed if d <= f returns falsy because of the short-circuit evaluation in the && operator, but I don’t think that makes sense given that the logic in the actual function would prevent d <= f from ever being false at that point in the code, and it’s clear from DOM-watching that func3 is being executed.
If you want to see the whole code, I found this in http://cdn.sstatic.net/js/full.js?v=9358063bfb40 as referenced by https://stackoverflow.com/faq in the moveScroller function (full function below, it’s in the line that has d <= f && j.css({...}) to reset back to a relative position).
function moveScroller() {
var g = $("#scroller").width(),
d = function () {
var d = $(window).scrollTop(),
f = $("#scroller-anchor").offset().top,
j = $("#scroller");
d > f ? j.height() > $(window).height() ? j.css({
position: "fixed",
top: "",
bottom: "0px",
width: g
}) : j.css({
position: "fixed",
top: "0px",
bottom: "",
width: g
}) : d <= f && j.css({
position: "relative",
top: "",
bottom: ""
})
};
$(window).scroll(d).resize(d);
d()
}
If either
dorfare non-numeric (NaN, non-number strings, etc) then both testsd > fandd <= fcan returnfalse.So in the code
at first glance it looks like
d <= fis redundant, but it will short-circuit the execution offunc3if eitherdorfis non-numeric.Ugly code!