Javascript merge options

I have an object that looks like this:

StandardFormat({ HeaderFont: 'greentext2', HeaderLinkFont: 'bluelink3', Backcolor: 'Black', ... }); 

So far, I have a function that takes the following form:

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

All parameters are listed and must be specified in the call. I would like to do this:

 FormatGrid(ID, Format){} 

So I could write something like this:

FormatGrid('TopGrid', StandardFormat) ; and be able to send a grid identifier and any format object.

I am stuck. How do you combine the parameters?

Thanks for your suggestions.

0
source share
1 answer

You can 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 .

It splits into window .

+2
source

Source: https://habr.com/ru/post/1345479/


All Articles