javascript - 这个 Javascript 函数参数是做什么的?

标签 javascript syntax

考虑以下代码(为了清晰起见缩短了):

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/

相关文章:

javascript - 检查给定的 5 位数字中的所有 5 位数字是否相同

haskell - 在 Haskell 实现中是否允许使用 Unicode 标识符是在哪里指定的?

javascript - 如何使用选择器在 Jquery 中的 foreach 循环中定位每个子级

javascript - 来自外部文件的模板文字

java - 是否可以在项目中更改 Java 语法?

php - 更新重复键上的复合键

cygwin 中的 bash 函数语法错误

java - Java中<>里面的数据类型有什么作用?

javascript - 使用 jQuery 和 ajax 从提交后填充表单

javascript - 如何检测节点是否从 DOM 中删除并返回索引位置