Reputation: 12529
I have a return statement that was used in this Stackover answer, that I can't quite understand. Here it is:
return maxWidth > $this.width() || maxHeight > $this.height();
What does it mean to return something in way?
I'll edit the title of this question after an answer as soon as I know what it is :)
Upvotes: 0
Views: 112
Reputation: 2140
It's known as short-circuit evaluation, and in this case will return a boolean value. If
maxWidth > $this.width()
is true, it'll return true
, without evaluating the second test. Otherwise it'll return the result of evaluating
maxHeight > $this.height().
Upvotes: 1
Reputation: 382102
It returns true if one of the dimension of $this
, which is a jQuery wrapper object created as $(this)
, is smaller than some variables.
In the code you link too, that enables the detection of overflowing as maxWidth
and minWidth
are the dimensions of the biggest child : if one child is bigger than this, then it is overflowing this.
Have a look at the width function.
Upvotes: 0
Reputation: 18064
It returns boolean
.
return maxWidth > $this.width() || maxHeight > $this.height();
Assume,
maxWidth = 300
$this.width() = 200
maxHeight = 400
$this.height() = 500
so it returns
(300>200 || 400>500) ==> (T || F) ==> TRUE
Upvotes: 3
Reputation: 1054
In that particular example the code is checking if the biggest child dimension exceeds the parent dimension, the dimensions being width and height.
Upvotes: 1
Reputation: 91299
It's the equivalent of:
if (maxWidth > $this.width() || maxHeight > $this.height()) {
return true;
} else {
return false;
}
In other words, if either maxWidth
is greater than the width()
of $this
or maxHeight
is greater than the height()
of $this
, it will return true
; otherwise, it will return false
.
Upvotes: 6
Reputation: 122
its a bool value, so if the maximum of width or height is greater than real width, then you get true.
Upvotes: 0