表达式 && 表达式语法是什么意思?

What does expression && expression syntax mean?

这一行 parent && (this.parent.next = this); 是什么意思? 它看起来只是坐在那里,什么都不做,而不是 if 语句或承诺或任何东西。这种编码风格有名称吗?

    var Particle = function(i, parent)
{
    this.next = null;
    this.parent = parent;
    parent && (this.parent.next = this);
    this.img = new Image();
    this.img.src = "http://www.dhteumeuleu.com/images/cloud_01.gif";
    this.speed = speed / this.radius;
}

它出现在我正在查看的这个动画文件中的多个位置。这是另一个例子.. (!touch && document.setCapture) && document.setCapture();

this.down = function(e, touch)
{
    e.preventDefault();
    var pointer = touch ? e.touches[0] : e;
    (!touch && document.setCapture) && document.setCapture();
    this.pointer.x = pointer.clientX;
    this.pointer.y = pointer.clientY;
    this.pointer.isDown = true;

shorthand

if (parent) {
    this.parent.next = this
}

if parent 为 false 则不弹出(this.parent.next = this),示例:

parent = false;
parent && alert("not run");

短路评估:

由于逻辑表达式是从左到右求值的,所以命名为"short-circuit"求值,

variable && (anything); // anything is evaluated if variable = true.
variable || (anything); // anything is evaluated if variable = false

可以用于变量赋值:

var name = nametemp || "John Doe"; // assignment defaults if nametemp is false
var name = isValid(person) && person.getName(); //assignement if person is valid