Passing arguments in anonymous functions in JavaScript

后端 未结 5 1135
遥遥无期
遥遥无期 2021-02-02 11:29

Sometimes I see JavaScript that is written with an argument provided that already has a set value or is an object with methods. Take this jQuery example for instance:



        
5条回答
  •  面向向阳花
    2021-02-02 12:02

    Yes, you are passing functions as arguments. The functions that you pass will of course have their own arguments.

    And, these arguments can be anything including objects which may have their own methods, etc.

    http.createServer will accept a function and it will know how may arguments that function has. One way to to do this is to check the arguments property of the passed in function. Or the api developer may have used the actual elements.

    The writer of this function will know what is expected as arguments and will document it in the api documentation.

提交回复
热议问题