函数长度
函数长度
一、只给形参(无默认值):
function f0() { }
console.log(f0.length)//0
function f1(a) { }
console.log(f1.length)//1
function f2(a, b) { }
console.log(f2.length)//2
function f3(a, b, c) { }
console.log(f3.length)//3
小结:
函数长度等于参数个数(没有默认值情况下)
二、添加默认值
function f1(a = 0) { }
console.log(f1.length)//0
function f2(a, b = 0) { }
console.log(f2.length)//1
function f3(a, b, c = 0) { }
console.log(f3.length)//2
function f4(a, b = 0, c) { }
console.log(f4.length)//1
小结:
函数的长度,就是第一个具有默认值之前的参数个数
三、特殊情况-剩余参数 ...args
function f1(name, ...args) {}
console.log(f1.length) // 1
小结:
剩余函数不计入函数长度内
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术