有人可以为我解释这个退货声明吗?

shr*_*ans 0 javascript

我有一个在这个Stackover答案中使用的return语句,我不太明白.这里是:

return maxWidth > $this.width() || maxHeight > $this.height();
Run Code Online (Sandbox Code Playgroud)

以某种方式退货意味着什么?

一旦我知道它是什么,我会在答案后编辑这个问题的标题:)

Joã*_*lva 7

它相当于:

if (maxWidth > $this.width() || maxHeight > $this.height()) {
  return true;
} else {
  return false;
}
Run Code Online (Sandbox Code Playgroud)

换句话说,如果有一个maxWidth比更大width()$this maxHeight比更大height()$this,它会返回true; 否则,它将返回false.

  • @Owen:不是真的,它只是不那么冗长,而且是一个返回`boolean`值的函数的常用习惯用法.例如,如果你有一个取整数的函数,如果整数大于5则返回`true`,否则返回'false`,你可以写`return i> 5`,这比`if更简洁(i> 5){return true} else {return false}`. (2认同)