Hi I am building a plugin which unfortunately has 146 options…
What is the best way to merge (cut down) options.
Sorry for my poor english.
Example:
Lets say we want to apply different color to two different elements.
Normal Default Options:
elemColor1:'black',
elemColor2:'red',
and use them like this:
elem1.css('color',options.elemColor1);
elem1.css('color',options.elemColor2);
or as array?
elemColor:['black','red'],
and use them like this:
elem1.css('color',options.elemColor[0]);
elem2.css('color',options.elemColor[1]);
or as object?
elemColor:{color1:'black',color2:'red'},
and use them like this:
elem1.css('color',options.elemColor.color1);
elem2.css('color',options.elemColor.color2);
if passed as Array or Object we have the problem that if we set other parameters than default and we forget the second argument of elemColor.
elemColor:['green'],
then jquery plugin cannot read default second value (red).
Which is better(performance, smaller file size, e.t.c)?
Is there any other way???
There is no doubt that objects are easier to manage and won’t cost you any significant performance in the long run. If you really have a lot consecutive options (color1, color2, color3, etc.), it may make sense to use an array as an object value. Just be sure to organize and comment well. Something like: