You are trying to do some type of what is called when the method overloads in some languages.
JavaScript does not support it in this way.
JavaScript is very versatile and allows you to use this feature in many ways.
In your specific example, your add function, I would recommend that you create a function that takes an arbitrary number of parameters using arguments .
jQuery.extend(jQuery, { add: function (/*arg1, arg2, ..., argN*/) { var result = 0; $.each(arguments, function () { result += this; }); return result; } });
Then you can pass any number of arguments:
alert(jQuery.add(1,2,3,4));
For a more complex method overload, you can determine the number of arguments passed and their types, for example:
function test () { if (arguments.length == 2) {
Check out the following article, it contains a very interesting method that uses some functions of the JavaScript language, such as closing, a functional application, etc., to simulate method overloads:
CMS
source share