Is it possible to reflect the arguments of a Javascript function?

后端 未结 8 1780
孤城傲影
孤城傲影 2020-12-02 23:21

Is it possible to get all of the arguments a Javascript function is written to accept? (I know that all Javascript function arguments are \"optional\")? If

8条回答
  •  半阙折子戏
    2020-12-02 23:46

    HBP's answer is what most people are looking for, but if you're the one defining the function, you can also assign a property to the function object. For example,

    a.arguments = ['foo', 'bar', 'baz']
    function a(foo, bar, baz) {
      // do stuff
    }
    

    This is debatably more clear, but you'll have to write your arguments twice.

提交回复
热议问题