How to detect a JavaScript function with a certain signature has been registered?

后端 未结 4 1217
抹茶落季
抹茶落季 2021-02-02 01:38

Say you have two functions with the following signatures:

  1. addClass( class )
  2. addClass( class, duration )
4条回答
  •  长情又很酷
    2021-02-02 02:07

    You can use the length property of the function object to check the signature. Example:

    function x(a) {}
    function y(a,b) {}
    
    alert(x.length); // shows "1"
    alert(y.length); // shows "2"
    

提交回复
热议问题