JavaScript 函数的length

详细参见博客

  • length 是函数对象的一个属性值,指该函数有多少个必须要传入的参数,即形参的个数,且仅包括第一个具有默认值之前的参数个数
    例如:
 console.log("function(a = 1, b, c)",(function(a = 1, b, c) {}).length); // 0
 console.log("function(a, b = 1, c)",(function(b, a = 1, c) {}).length); // 1
  • arguments.length 是函数被调用时实际传参的个数
    如:
console.log("fun (1,2,3) :arguments.length",(function(a = 1, b, c) {return arguments.length})(1,2,3)) // 3

猜你喜欢

转载自blog.csdn.net/Wind_waving/article/details/106814448
今日推荐