开发者

javascript merging parameters

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜