Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 22
    Perhaps it would be useful to ask why you think you need function overloading to begin with. I think that will get us closer to a real solution. Commented Jan 19, 2009 at 0:41
  • 1
    This is closed, but I do the following: this.selectBy = { instance: selectByInstance, // Function text: selectByText, // Function value: selectByValue // Function }; Commented Jun 22, 2012 at 20:46
  • My answer shows how to do run time function overloading, it has a speed penalty and I wouldn't advise doing it to get around Javascript's specification. Function overloading is really a compile time task, I only provide the answer for academic purposes and leave it up to your own discretion as to whether or not to employ it in code. Commented Oct 23, 2012 at 22:57
  • 2
    Just in case it is useful, I've built a lightweight js framework that allows for type-based method overloading. Obviously the same caveats apply with regards to performance, but it's worked well for my needs so far and still has quite a lot of room for improvement: blog.pebbl.co.uk/2013/01/describejs.html#methodoverloading Commented Jan 15, 2013 at 0:24
  • 4
    Closed because it's opinion based, and yet it has 871 upvotes. That means something Commented Jun 2, 2022 at 17:11