答案 0 :(得分:3)
将radius
转换为整数值,因为|
是位运算符(强制为32位整数值)。
radius |= 0
等同于
radius = (castToInt32(radius > 0 ? Math.floor(radius) : Math.ceil(radius))) | 0
如果存在castToInt32()
这样的功能。 | 0
是一种习惯性的JavaScript方式来做同样的事情。操作本身是一个无操作,因为对0
的每个位进行OR运算将返回相同的位(1 | 0 == 1
,0 | 0 == 0
),好处是值的转换。< / p>