gpt4 book ai didi

javascript - 这个 bool 表达式如何计算?

转载 作者:行者123 更新时间:2023-11-28 12:08:40 25 4
gpt4 key购买 nike

From Three.js:

this.sides.px && buildPlane( 'z', 'y',   1 * flip, - 1, depth, height, - width_half, this.materials[ 0 ] ); // px
this.sides.nx && buildPlane( 'z', 'y', - 1 * flip, - 1, depth, height, width_half, this.materials[ 1 ] ); // nx
this.sides.py && buildPlane( 'x', 'z', 1 * flip, 1, width, depth, height_half, this.materials[ 2 ] ); // py
this.sides.ny && buildPlane( 'x', 'z', 1 * flip, - 1, width, depth, - height_half, this.materials[ 3 ] ); // ny
this.sides.pz && buildPlane( 'x', 'y', 1 * flip, - 1, width, height, depth_half, this.materials[ 4 ] ); // pz
this.sides.nz && buildPlane( 'x', 'y', - 1 * flip, - 1, width, height, - depth_half, this.materials[ 5 ] ); // nz

这个 bool 表达式返回什么?如果它返回一个 bool 值,它去了哪里?(我没有看到作业!)它如何评估?

最佳答案

你说得对,没有任务。这些语句利用了 && 运算符所使用的优化。如果右侧和左侧的计算结果都为 true,则 && 运算符的计算结果为 true。因此,如果左侧为 false,它甚至不必检查右侧,因为无论如何结果都是 false,并且根本不会对其进行评估。

因此,这段代码:

this.sides.px && buildPlane( 'z', 'y',   1 * flip, - 1, depth, height, - width_half, this.materials[ 0 ] ); // px

相当于这段代码:

if (this.sides.px) {
buildPlane( 'z', 'y', 1 * flip, - 1, depth, height, - width_half, this.materials[ 0 ] );
}

关于javascript - 这个 bool 表达式如何计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6638478/

25 4 0
文章推荐: css - IonicPopup 在调用时更改背景颜色
文章推荐: css - 包含 bootstrap.css.map 的正确方法?
文章推荐: 内带有 SVG 的 CSS 选择器特异性