J
John Smith
can we overload a javascript function with different argument?
example:
function a(a){}
function a(a,b){}
example:
function a(a){}
function a(a,b){}
John said:can we overload a javascript function with different argument?
example:
function a(a){}
function a(a,b){}
can we overload a javascript function with different argument?
example:
function a(a){}
function a(a,b){}
Winter said:1) Optional arguments
If a method is defined as taking optional arguments, you can add
the defaults by taking advantage of ECMAScript's rather different
logical OR (||) operator:
function myFunction(a, b) {
b = b || 'default';
}
If the argument, b, evaluates to false (that is, zero (0), empty
string (''), null, undefined, or false), the second operand will
be assigned in its place.
[snip]function myFunction(a, b) {
b = b || 'default';
}
That means that if the default is not zero, etc., it is impossible to
give and get used a parameter which is zero, etc.
How about if (b==null) b = 'default' ?
not for a value which, like that of var U , is undefined, which needs b===null .
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.