Function overloading in Javascript - Best practices

后端 未结 30 1490
难免孤独
难免孤独 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 03:57

    There are two ways you could approach this better:

    1. Pass a dictionary (associative array) if you want to leave a lot of flexibility

    2. Take an object as the argument and use prototype based inheritance to add flexibility.

提交回复
热议问题