I'm writing a javascript function that has a pretty long list of parameters:
FormatGrid(ID, BackColor, SideColor, HiddenColor, SmallTextClass....)
It works well but it's getting somewhat painful when calling this function to remember each parameter and the order they go in because the function takes a total of 9 parameters (and I might add 2 more).
I'm wondering if there's an elegant solution to this.
Thanks for your suggestions.
you can just pass in an Object
FormatGrid(myObject){
//your code
}
Where your myObject is something like {ID: '1', BackColor: 'red', SideColor: 'red', HiddenColor: 'black', SmallTextClass: 'true'...}
Generally I like the following format
function foo(requiredVar1,requiredVar2,..,options) {
//here is where options is merged with default params
var defaultOptions = {};
options = Object.extend(defaultOptions,(options || {}));
}
where options is a map {option1:value1, ...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With