In Douglas Crockford's book "Javascript: The Good Parts", he mentions Object Specifiers in passing values to a new object. Essentially, instead of passing parameters to a function in a certain order, he suggests passing an object with the parameters contained within, like so:

var myObject = someFunction({a: 1, b: 2, c: 3});

What isn't explained, however, is how to handle those parameters after they've been passed through. Instead of doing the following to set up default values:

function someFunction(params){
    this.a = params.a || 0; 
    this.b = params.b || 0;
    ...
}

What's another way to handle a large amount of parameters without being as verbose?


EDIT: Looking at the answers below, the use of the for-in loop is a great option. What's another way to do it while setting different default values for each property? Is there a way to create an object with various default values and compare against that?

Edit
Report