Function overloading in Javascript - Best practices

后端 未结 30 2177
难免孤独
难免孤独 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:04

    The first option really deserves attention cause it's the thing I've come up in quite complex code setup. So, my answer is

    1. Using different names in the first place

    With a little but essential hint, names should look different for computer, but not for you. Name overloaded functions like: func, func1, func2.

提交回复
热议问题