Allowing javascript function to accept any number of arguments

后端 未结 6 1779
难免孤独
难免孤独 2020-12-29 05:28

I would like the below function to be more flexible and accept multiple callbacks to other functions if they are defined in the arguments.

$(function() {
            


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 06:02

    Yes this is possible, here's an example :

    function myfunct()
    {
    
      var arguments = myfunct.arguments;
    
      for (var i = 0; i < arguments.length; i++)
            {
    
                    alert("Argument " + i + " value = " + arguments[i]);
    
                }
    
    }
    

    You can call this fonction by any number of arguments :

    myfunct("foo");
    
    myfunct("foo","bar");
    

提交回复
热议问题