Is it possible to set default values of parametrs for own functions in jquery?
A:
One way to do this is to check the parameters. For example:
function test(paramA) {
if (paramA == null) {
paramA = defaultValue;
}
// use paramA here
}
Another possibility is this:
function test() {
var paramA = defaultValue;
if (arguments.length == 1) {
paramA = arguments[0];
}
// use paramA here
}
Darin Dimitrov
2010-03-14 16:21:51
A:
You might want to check for undefined
instead of null
.
var f=function(param){
if(param===undefined){
// set default value for param
}
}
Jeremy
2010-03-14 16:24:09
Thanks a lot. It is what I find.
sev
2010-03-14 16:36:36