views:

50

answers:

1

I am writing an email to some colleagues and trying to describe the pattern that jQuery uses to pass parameters, which is to encapsulate them in an "options object", like so:

var options = { chartType: "line", color: "red", width: 200 };
jQuery("#something").somePlugin(options);

But I'm having a hard time calling them "options objects"... seems like there should be a more formal name. What would you call them?

Thanks!

+1  A: 

It's an object literal. I would describe it as either assigning an object literal to a variable and passing that in

var options = { option1: 'option1', option2: 'option2' }

$('#thing').doSomething(options);

or declaring an object literal inline as an argument to the jQuery plugin/command

$('#thing').doSomething({ option1: 'option1', option2: 'option2' });

I would say that it's a way of being able to pass multiple parameters into a jQuery method and also point out that a lot of plugins have default values that can be overridden by passing in an options object literal. Than explain how $.extend() is used to combine default properties and those from the options passed in to set a properties object that will be used inside of the jQuery method.

Russ Cam