Function oveloading in JavaScript

I was trying to get different behavior from the function depending on its arguments, a feature found in various programming languages such as Ada, C++, C#, Delphi, D, and Java, that allows creating several methods with the same name which differ from each other in the type of the input and the output of the function” – but not in JavaScript. It has been argued that method overloading is not such a good idea (Bertrand Meyer: Overloading vs Object Technology), and in JavaScript using different function names seems to be a right way to go…

But, the interface for the user of this api in that case would look like this:

[gist /]

but I didn’t want that. I wanted this:

[gist /]

Turned out to be easy to add a wrapper on top of the explicitly named api:

[gist /]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: