考虑以下代码(为了清晰起见缩短了):
Vertices.chamfer = function(vertices, radius, quality, qualityMin, qualityMax) {
radius = radius || [8];
if (!radius.length)
radius = [radius];
};
我将第一部分读为(伪代码):
if (radius array passed to function) then
radius = radius
else
radius = [8] // new array, single element of value 8
end if
但我没有得到第二个表达式(if(!radius.length) radius = [radius]
部分)。
谁能给我解释一下吗?
最佳答案
Vertices.chamfer = function(vertices, radius, quality, qualityMin, qualityMax) {
// Set the radius to the value passed in.
// If the value passed in is undefined, set the radius to an
// array containing 8 (the "default")
radius = radius || [8];
// If radius isn't an array (i.e. length is 0 which evaluates to false),
// make it an array.
if (!radius.length)
radius = [radius];
};
关于javascript - 这个 Javascript 函数参数是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35537071/