views:

29

answers:

2

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
A: 

You might want to check for undefined instead of null.

var f=function(param){
  if(param===undefined){
    // set default value for param
  }
}
Jeremy
Thanks a lot. It is what I find.
sev