Counting parameters in Javascript

前端 未结 2 484
感情败类
感情败类 2021-01-16 07:53

What the docs at Mozilla says:

  console.log((function(...args) {}).length); 
  // 0, rest parameter is not counted

  console.log((function(a, b = 1, c) {})         


        
2条回答
  •  忘掉有多难
    2021-01-16 08:52

    Not sure if this answers what you were asking... based on your examples though...

    var x = function (...args) {
      //console.log(Object.keys(args).length);
      //console.log(Object.keys(arguments).length);
      console.log(arguments.length);
    }
    

    https://jsfiddle.net/hxm4smc1/555/

提交回复
热议问题