开发者

javascript merging parameters

开发者 https://www.devze.com 2023-02-20 08:31 出处:网络
I have an object that looks like this: 开发者_C百科StandardFormat({ HeaderFont: \'greentext2\', HeaderLinkFont: \'bluelink3\',

I have an object that looks like this:

开发者_C百科StandardFormat({
    HeaderFont: 'greentext2',
    HeaderLinkFont: 'bluelink3',
    Backcolor: 'Black',
        ...
});

So far, I have a function that has this form:

FormatGrid(ID, HeaderFont, HeaderLinkFont, BackColor,...){}

All the parameters are listed and must be supplied in the call. What I'd like to do is replace it with this:

FormatGrid(ID, Format){}

That way, I could write something like this:

FormatGrid('TopGrid', StandardFormat); and be able to send the id of the grid and any format object.

I'm kinda stuck. How do you merge the parameters?

Thanks for your suggestions.


You could do...

function FormatGrid(ID, Format) {
    var options;
    if (typeof Format != 'string') {
       options = Format;
    } else {
       options = {
          HeaderFont: arguments[1],
          HeaderLinkFont: arguments[2],
          Backcolor: arguments[3]
       }
    }

    // Here you could then access `options.HeaderFont`.
}

jsFiddle.

This unpacks to window however.

0

精彩评论

暂无评论...
验证码 换一张
取 消