Function overloading in Javascript - Best practices

后端 未结 30 1485
难免孤独
难免孤独 2020-11-22 03:33

What is the best way(s) to fake function overloading in Javascript?

I know it is not possible to overload functions in Javascript as in other languages. If I neede

30条回答
  •  抹茶落季
    2020-11-22 04:10

    check this out. It is very cool. http://ejohn.org/blog/javascript-method-overloading/ Trick Javascript to allow you to do calls like this:

    var users = new Users();
    users.find(); // Finds all
    users.find("John"); // Finds users by name
    users.find("John", "Resig"); // Finds users by first and last name
    

提交回复
热议问题